Treat server data as a cache, not state: deduplicate requests, serve stale data while revalidating, avoid race conditions, and invalidate after mutations. Then build a small query cache yourself.
Most frontend "state" bugs are really cache bugs. A list of todos fetched from your API isn't owned by the browser. The server owns it, and the browser holds a copy that starts going out of date the moment it arrives.
Treating that copy like ordinary client state (useState + useEffect + fetch in every component) leads to the same problems in every codebase:
The fix is to separate two kinds of state:
| Client state | Server state | |
|---|---|---|
| Owner | The browser | The server |
| Examples | Open modal, form input, selected tab | Users, todos, search results |
| Can go stale? | No | Yes, constantly |
| Right tool | useState, context, a store | A query cache |
Libraries like TanStack Query, SWR, RTK Query, and Apollo Client are all query caches. In this tutorial you'll build the core ideas yourself, so you understand exactly what those libraries do and can choose their settings with confidence.