Part III — The Speed · Lesson 6.10
State Management
In one lineSort state by who owns it — server, URL, or client — and most of the hard problem disappears.
Where you've seen itCopying a filtered search URL into Slack and having a colleague open the identical view.
Diagram
Lessons in this diagram6.9 API Caching
How it works
- Classify first. Ask "who is the source of truth?" Server state gets a caching library, not a global store.
- Push filters and pagination into the URL — you get shareability, deep links, and back-button behaviour for free.
- Keep client state as local as possible, lifting only when a second consumer genuinely appears.
- Use Context for low-frequency, wide-reach values (theme, auth, locale); use a store with selectors for anything that changes often.
- Derive, don't duplicate. Totals, filtered lists, and counts should be computed from state, never stored alongside it.
Trade-offs
| Tool | Fits | Cost |
|---|---|---|
useState | Local UI | Prop drilling if over-lifted |
| Context | Theme, auth, locale | Re-renders all consumers |
| Zustand | Global client state, small API | Another concept in the codebase |
| Redux Toolkit | Large apps, devtools, middleware | Boilerplate, learning curve |
| React Query | All server state | Not for client-only state |
Interview angle
"Which state management library would you choose?"
- Reframe first: most of the state is server state, so the real answer is a caching library plus the URL.
- What's left is genuinely small — theme, modals, cart — and
useStateplus one lightweight store usually covers it. - Choose Redux when you need time-travel debugging, middleware, or a large team needing strict conventions — not by default.
Recap
- Server, URL, client, form — classify before choosing a tool.
- Filters and pagination belong in the URL, not in a store.
- Context broadcasts; stores let components subscribe selectively.