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);
}
}- Open the previous project and record its result.
- Type the example and complete: Trigger success, empty, and error paths; prevent duplicate clicks while loading.
- Change one input, predict, then verify.
- 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
| Symptom | What to check |
|---|---|
| Unexpected result | Do not swallow errors; show a useful message and preserve debug information. |
| Nothing changes | Save, 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