Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

loading-error-states

Loading and error states

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
advanced

This lesson

This lesson teaches Loading and error states: the concepts, APIs, and habits you need before advancing in React.

Local component state is the backbone of interactive UI; mistakes here cause subtle re-render bugs.

You will apply Loading and error states in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When hooks, state, and effects from intermediate lessons are familiar.

Async UI needs explicit states: idle/loading, success, and error. Users should never stare at a blank screen wondering if anything happened.

State machine mindset

  • Start loading before the request
  • On success: store data, clear error, stop loading
  • On failure: store an error message, stop loading, keep or clear stale data intentionally
  • Offer retry for transient failures

UI patterns

Disable buttons while loading, show skeletons or spinners, surface errors near the action that failed, and log details with printOutput while learning.

Important interview questions and answers

  1. Q: One boolean or status enum?
    A: Enums like 'idle' | 'loading' | 'error' | 'success' prevent impossible combos like loading and error simultaneously.
  2. Q: Where to put fetch logic?
    A: Custom hooks or data libraries in apps; useEffect in learning examples and small components.

Self-check

  1. Why separate loading and error UI branches?
  2. What should a Retry button do?

Challenge

Retry flow

  1. Click Run — first load may fail (simulated).
  2. Press Retry until data loads.
  3. Confirm error message clears on success.

Done when: error UI appears on failure and successful retry shows data.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Error UI pattern?
  • Retry approach?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump