Loading, empty, and error states

Render loading, empty, success, and failure states explicitly.

Difficulty
beginner
Time
45 minutes
Last verified
9/21/2026

What you will build

Render loading, empty, success, and failure states explicitly.

Understand the idea first

Render loading, empty, success, and failure states explicitly.

Build it step by step

async function refresh() {
  showStatus('loading');
  try {
    const items = await loadData(endpoint);
    render(items);
    showStatus(items.length ? 'ready' : 'empty');
  } catch (error) {
    showStatus('error', error.message);
  }
}
  1. Open the previous project and record its result.
  2. Type the example and complete: Trigger success, empty, and error paths; prevent duplicate clicks while loading.
  3. Change one input, predict, then verify.
  4. Create and repair: Do not swallow errors; show a useful message and preserve debug information.

Read the important lines

  • Render loading, empty, success, and failure states explicitly.
  • Read input, processing, and output separately.
  • Verify another input and an edge case.

Common mistakes and what to check

SymptomWhat to check
Unexpected resultDo not swallow errors; show a useful message and preserve debug information.
Nothing changesSave, verify paths, and read the first relevant Console error.

Practice without copying

Trigger success, empty, and error paths; prevent duplicate clicks while loading.

Check the answer after you try

Rebuild and explain the decisions. Check: Do not swallow errors; show a useful message and preserve debug information.

Completion check

  • I produced the required visible result
  • I can explain the input, processing, and output
  • I tested normal, edge, and failure cases

Your privacy choices

Necessary storage is always on. Optional analytics and support services load only after consent.