Every network request has at least three UI states: loading, error and success (and often empty). Handle all of them explicitly. Fetching in an effect Track loading, error and data. Use an AbortController to cancel the request when the component unmounts or the input changes — this prevents race conditions where an old, slow response overwrites a newer one. Check response.ok; fetch does not reject on HTTP errors. In production apps Hand-written effects get complex quickly (caching, retries, refetch on focus, pagination). Use a data library: Library Highlights TanStack Query caching, background refetch, mutations, devtools SWR lightweight stale-while-revalidate RTK Query integrated with Redux Toolkit Framework loaders Next.js Server Components, React Router loaders React 19's use(promise)…
Key Takeaways
Always render loading, error and success states.
Abort in-flight requests in the effect cleanup to avoid race conditions.
Check response.ok — fetch only rejects on network failures.
Use TanStack Query/SWR for caching and refetching in real apps.