Skip to content
Learn Netverks

Lesson

Step 19/36 53% through track

fetch-data

Fetching data

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

This lesson

This lesson teaches Fetching data: the concepts, APIs, and habits you need before advancing in React.

Data fetching patterns appear in every dashboard; loading and error states are not optional polish.

You will apply Fetching data in contexts like: Dashboards, live tables, and detail pages backed by REST or GraphQL APIs.

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 you can explain the previous lesson's ideas without copying starter code.

Data fetching belongs in useEffect (or modern data libraries built on the same ideas). In this playground we simulate an API with setTimeout to avoid CORS and network failures while you learn the pattern.

Typical flow

  1. Set loading true when a fetch starts
  2. Store results in state when data arrives
  3. Capture errors in state or show a fallback UI
  4. Abort or ignore stale responses if the user navigates away

Production note

Real apps use fetch, React Query, SWR, or server components in Next.js. The state machine—loading, data, error—is the same regardless of transport.

Self-check

  1. Why fetch inside useEffect instead of directly in the component body?
  2. What goes wrong if you forget to handle the loading state?

Challenge

Simulated API

  1. Click Run and wait for the mock posts to appear.
  2. Change the delay to 1500ms and observe longer loading.

Done when: loading shows first, then a list of mock posts renders.

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

  • Loading UI you added?
  • Mock vs real API?

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