ipi.
← React Field Guide

Concept 11 of 11

Data Fetching

✦ Tap any highlighted term to learn more

Most real apps need to load data from an . The basic React pattern is fetch inside with three : loading, error, and data. You show different UI depending on which you're in.

The fetch lives inside with the right dependency so it doesn't run on every . If you're fetching based on a (like a userId), add that to the dependency — the fetch re-runs whenever it changes.

Always handle the three cases: while loading, show a spinner or placeholder. If something went wrong, show the error clearly. Only the real data when it's actually there — otherwise you'll get crashes from trying to access on null.

For production apps, consider a like TanStack Query (React Query) that handles caching, refetching, and deduplication for you. The manual pattern here is the foundation — understanding it makes those tools much easier.