Server State for Reacts
Server state is data that lives on a backend and is only borrowed by the UI, so it can be stale, loading or failed. Libraries like TanStack Query fetch it, cache it by key, refetch it and handle mutations, which is cleaner than hand-written useEffect and useState combinations.
Stage: Data and Routing · Part of the React roadmap · Last reviewed 19 November 2026
What to learn in Server State
- Fetch JSON in a component and handle loading and error states
- Cancel or ignore stale requests to avoid race conditions
- Use a query key to cache and share fetched data
- Send a POST or PUT as a mutation and invalidate affected queries
- Apply an optimistic update and roll back on failure
- Distinguish server state from client UI state
Server State interview questions
Why is fetching inside useEffect with useState error-prone?
You must handle loading, errors, cancellation, race conditions between requests and caching yourself. Without that, stale responses can overwrite newer ones and the same data is refetched repeatedly. Query libraries solve these cases consistently.
What is an optimistic update?
It updates the UI immediately as if a mutation succeeded, then confirms or rolls back when the server responds. It makes interactions feel instant, but needs rollback logic and a refetch so the screen matches the real data.
Where Server State fits in the React roadmap
Server State belongs to the Data and Routing stage (intermediate level), which takes about 25 hours. Connect to the world.
Other units in this stage
Back to the full React roadmap