Part 6 has handed you a lot of tools: useState and useReducer, Context, a store you built yourself, Redux Toolkit, Zustand, Jotai, MobX and Valtio, XState, TanStack Query and SWR, the URL, React Hook Form. Each chapter showed what one tool does well. This one is about choosing, which is what interviewers actually probe: not "how does Zustand work" but "what would you use here, and why not the alternative?"
The short version of the chapter: most state management decisions are decided by what kind of state it is, not by which library you like. Classify first and the library choice usually becomes small and obvious. Then take a stance, and be ready to name what it costs.
The problem: one store for everything#
Here's a store that grew the way stores grow. Everything that more than one component touched went into it.
export const useAppStore = create<AppState>((set, get) => ({
books: [], // from the API
booksLoading: false,
booksError: null,
booksFetchedAt: 0,
filterTag: "all", // also in the URL... sometimes
searchText: "",
unreadCount: 0, // recomputed in three different actions
newBookDraft: { title: "", author: "" },
newBookErrors: {},
isAddDialogOpen: false, // only the dialog uses this
theme: "light",
cart: [],
// ...and forty actions that keep all of the above consistent
}));Each field is defensible on its own. Together they cause the bugs from earlier chapters: server data that never refetches (Server state), a filter that doesn't survive a refresh (URL and form state), a derived count that goes stale whenever someone forgets to update it, a draft form that re-renders half the app on every keystroke, and dialog state that's global for no reason. The store isn't the problem. Putting six kinds of state in one place, with one set of tools, is.
Four questions to ask about any piece of state#
1. What kind of state is it?#
The categories from Kinds of state, each with its natural home:
| Kind | Example | Home |
|---|---|---|
| Server | the books, the current user record | a query cache (TanStack Query, SWR, RTK Query) or Server Components |
| URL | filters, search, page, selected tab | search params |
| Form | draft values, touched, errors, submitting | the form: uncontrolled inputs, React Hook Form, Actions |
| Derived | unread count, filtered list, totals | nowhere: compute it during render |
| Local UI | dropdown open, hover, input focus | useState in the closest component |
| Shared client | cart, editor document, multi-step wizard, selection across panels | lifted state, Context, or a client store |
| Persisted client | preferences, a draft you shouldn't lose | a client store with persistence, or the server |
The first four categories account for most of what people put in global stores. Once they go to their own homes, the "shared client state" left over is usually small.
2. How widely is it shared?#
Keep state as close as possible to where it's used, and move it up only when you must. One component: useState. A few siblings: lift it to the common parent. A subtree a few levels deep: pass props (two or three levels of props is fine, not a smell) or use Context. Many distant components across the app: a store.
3. How often does it change?#
This decides between Context and a store. Context re-renders every consumer whenever its value changes, with no way to subscribe to part of it. That's harmless for values that change a few times per session (theme, locale, the signed-in user) and expensive for values that change per keystroke or per animation frame, read by many components. Stores give you selectors (or atoms, or tracked reads), so each component re-renders only when its slice changes.
4. Who owns it?#
If the server owns it, your copy is a cache and needs cache behavior. If the URL owns it, components derive from the URL. If the user's browser owns it (a preference), you decide how to persist it. If a component owns it, nobody else should be able to set it. Ownership tells you where writes go, and two owners for the same fact is how copies drift.
Books come from the server and other people change them. Server state: a query cache, or fetch them in a Server Component.
The map is a default, not a law. Real answers include combinations: the search text is URL state, the results are server state keyed by that text, and the highlighted row is local state.
The tools, mapped to the jobs#
| Tool | Reach for it when | Watch out for |
|---|---|---|
useState / useReducer | state owned by one component or a small subtree | lifting too high, re-rendering big subtrees |
| Context | rarely changing values read widely; injecting a store instance | every consumer re-renders on every change |
| Zustand | shared client state with selectors and almost no ceremony | selecting new objects without useShallow; module singletons in SSR |
| Redux Toolkit | big teams wanting one enforced pattern, middleware, time-travel DevTools, RTK Query | ceremony for small apps |
| Jotai | many small independent pieces with derived values; bottom-up state | atom sprawl without conventions |
| MobX / Valtio | mutable domain models, automatic dependency tracking | forgetting observer or reading outside tracking |
| XState | flows: wizards, checkout, auth, retries, timeouts | ceremony for simple toggles |
| TanStack Query / SWR | anything that comes from a server | copying query data into other state |
| URL / nuqs | shareable, navigable view state | trusting unparsed params |
| React Hook Form + Zod | non-trivial forms | mixing controlled and registered inputs |
Context versus a store, live#
Here's the frequency question in code. Both versions hold a theme and a fast-changing counter. With Context, one value means one subscription, so the theme label re-renders on every increment. With Zustand, each component selects its slice.
import { createContext, useContext, useState } from "react";
import { create } from "zustand";
import { Rendered } from "guide-tools";
// --- Context: one value, every consumer subscribes to all of it
const AppContext = createContext<{ theme: string; count: number; inc: () => void } | null>(null);
function ContextProvider({ children }: { children: React.ReactNode }) {
const [count, setCount] = useState(0);
const value = { theme: "light", count, inc: () => setCount((c) => c + 1) };
return <AppContext value={value}>{children}</AppContext>;
}
function CtxTheme() {
const { theme } = useContext(AppContext)!;
return <Rendered label="Context: theme label">theme: {theme}</Rendered>;
}
function CtxCounter() {
const { count, inc } = useContext(AppContext)!;
return (
<Rendered label="Context: counter">
<button onClick={inc}>+1</button> {count}
</Rendered>
);
}
// --- Store: each component selects only what it reads
const useStore = create<{ theme: string; count: number; inc: () => void }>((set) => ({
theme: "light",
count: 0,
inc: () => set((s) => ({ count: s.count + 1 })),
}));
function StoreTheme() {
const theme = useStore((s) => s.theme);
return <Rendered label="Store: theme label">theme: {theme}</Rendered>;
}
function StoreCounter() {
const count = useStore((s) => s.count);
const inc = useStore((s) => s.inc);
return (
<Rendered label="Store: counter">
<button onClick={inc}>+1</button> {count}
</Rendered>
);
}
export default function App() {
return (
<>
<ContextProvider>
<CtxTheme />
<CtxCounter />
</ContextProvider>
<StoreTheme />
<StoreCounter />
</>
);
}You could split the Context into a theme context and a counter context, and for two values that's the right fix. The point is the trend: as the number of independently changing values and readers grows, splitting contexts turns into building a store by hand, which is what Build a store did.
The four interview questions#
These come up in nearly every React interview past junior level. Each answer below takes a position, gives the reason, and names the cost. Say them in your own words.
"Redux or Zustand?"#
For a new app: Zustand by default, Redux Toolkit when its structure pays for itself.
Once server data lives in a query cache and URL and form state live where they belong, the remaining client state is usually small: a cart, some cross-page UI, maybe an editor. Zustand covers that with a hook, selectors and optional middleware (persist, devtools, immer), no provider required, and very little code. It's also easy to delete later.
Redux Toolkit earns its extra structure in specific situations: a large team that benefits from one enforced pattern (every change is an action through a reducer), complex cross-cutting logic in middleware or listeners, strong use of DevTools time travel and action logs for debugging, or an existing Redux codebase where RTK Query can replace hand-written fetching. RTK removed most of the old boilerplate, so "Redux is verbose" is a weak argument now. "We don't need what it adds" is the strong one.
The cost of Zustand's freedom is consistency: without conventions, every developer writes stores differently. The cost of Redux is ceremony and indirection for teams that won't use its features.
"Context or a store?"#
Context is a dependency-injection mechanism, not a state manager. It passes a value down without props. It doesn't hold state (that's still useState or useReducer in a provider), and it can't let a consumer subscribe to part of the value.
So: use Context for values that change rarely and are read widely (theme, locale, auth user, feature flags) and for injecting instances (a store, a query client, an XState actor) into a subtree. Use a store for shared state that changes often and is read by many components, because selectors keep re-renders proportional to what changed. Splitting contexts and memoizing the value help, and the React Compiler removes the accidental re-renders inside consumers, but it can't stop a consumer from re-rendering when the context value it reads changes.
A good nuance to add: "Context plus useReducer" is a perfectly good store for a small app or a feature-scoped subtree. You switch when re-renders become measurable, not before.
"Why not keep server data in Redux?"#
Because server data needs a cache, and a store is just a place to put things. Server data is a snapshot of something you don't own: other people change it, and it goes stale. Keeping it correct needs request deduplication, a freshness policy, refetching on focus and reconnect, invalidation after mutations, race handling, retries and garbage collection. In Redux you write that per endpoint, and teams usually implement half of it.
A query library makes those behaviors declarative: a key, a staleTime, invalidateQueries after a mutation. If the team wants to stay in Redux, RTK Query is the answer: same cache semantics, living in the Redux store. Either way the hand-written loading/error/data slices disappear, and Redux keeps only genuinely client-owned state.
"Do we still need a state library with Server Components?"#
Less of one, and for different reasons. With Server Components, a lot of server state never reaches client state: the server fetches the books and renders them, and the framework's cache plus revalidation after Server Actions replaces much of what a client query cache did for read-mostly pages. URL state becomes something the server reads directly (searchParams). Forms submit to Server Functions, with useActionState and useOptimistic covering pending and optimistic UI.
What remains is client state for interactivity, which is mostly local: open panels, selections, drafts. A global client store becomes optional, and often small. A client query cache is still the right tool for highly interactive data on the client: polling, infinite scroll, optimistic updates shared by many components, offline support.
Two senior caveats. Stores and Context only work in Client Components, so the store lives below a "use client" boundary. And on the server, a module-level store is shared by every request, so a Zustand store created at import time can leak one user's data into another user's HTML. In SSR apps, create stores per request inside a provider (Zustand's docs show createStore plus Context for this).
Smells to point out in a code review#
- Derived state in state.
unreadCount,filteredBooks,isValidstored alongside their inputs. Compute during render; memoize only if it's measurably expensive. - State copied from props, the URL or a query into
useState. One owner, everything else derived. - Loading and error flags next to fetched data in a client store. That's a cache being rebuilt by hand.
- Global state for local UI. A dialog's
isOpenin the app store makes every change global and every bug harder to localize. - One giant Context value that changes often. Split it, or use a store.
- Fear of props. Passing a prop two or three levels is fine. Reaching for global state to avoid it is a bigger cost.
- A library per feature. Redux here, Zustand there, Jotai for one screen. Pick one client store per app and the right tools for the other kinds.
Pitfalls#
Check your understanding#
A dashboard shows sales from an API. The user picks a date range, and colleagues should be able to open the same view from a link. Where do the date range and the sales data live?
The unread count goes wrong after you toggle a book. Fix it by removing state, not by adding updates.
import { useState } from "react";
import { books as initial } from "guide-tools";
type Book = (typeof initial)[number] & { read: boolean };
export default function App() {
const [books, setBooks] = useState<Book[]>(initial.slice(0, 4).map((b) => ({ ...b, read: false })));
const [unread, setUnread] = useState(4);
function toggle(id: number) {
setBooks(books.map((b) => (b.id === id ? { ...b, read: !b.read } : b)));
setUnread(unread - 1); // assumes every toggle marks a book as read
}
return (
<div>
<p>Unread: {unread}</p>
<ul>
{books.map((b) => (
<li key={b.id}>
<label>
<input type="checkbox" checked={b.read} onChange={() => toggle(b.id)} /> {b.title}
</label>
</li>
))}
</ul>
</div>
);
}Which of these is a good fit for plain Context, without a store library?
An interviewer asks: "We're starting a new React app. Redux or Zustand?" Give your recommendation and its trade-offs.
An interviewer asks: "With Server Components, do we still need state management libraries?"
Interview angle
I choose state tools by classifying the state first. Server data goes in a query cache or Server Components, view state worth sharing goes in the URL, form drafts stay in the form, derived values are computed during render, and local UI state stays in useState. What's left is shared client state. Then I ask how widely it's shared, how often it changes and who owns it. Context suits rarely changing values read widely; a store with selectors suits frequently changing shared state. For a new app I'd default to Zustand for that small remainder and pick Redux Toolkit when its structure and tooling pay off.
Redux or Zustand for a new app?
Does the React Compiler fix the re-render cost of Context?
A team is committed to Redux and keeps API responses in hand-written slices with loading and error flags. What do you propose, without telling them to drop Redux?
Do we still need state management libraries with Server Components?
Is it ever right to copy a prop into state?
A product search page has results from an API, filters, a sort order, a selected row, a compare tray that persists across pages, a draft review form and a results count. Where does each piece live?
Recap#
- Classify before choosing: server, URL, form, derived, local, shared client, persisted. Each kind has a natural home, and most state doesn't belong in a global store.
- Then ask how widely it's shared, how often it changes and who owns it. Keep state as local as possible; one owner per fact, everything else derived.
- Context is for rarely changing values and injecting instances; stores are for frequently changing shared state, because selectors limit re-renders.
- New app: Zustand for the small amount of shared client state by default; Redux Toolkit when its structure, middleware and tooling pay off, with RTK Query for server data.
- Server data belongs in a cache, not a store. With Server Components, client state shrinks further, and server-rendered stores must be created per request.
Sources#
- react.dev: Choosing the state structure, Sharing state between components, Passing data deeply with context, You might not need an effect
- Redux: Why Redux Toolkit is how to use Redux today, RTK Query overview
- Zustand: Introduction, Setup with Next.js
- TanStack Query: Does this replace client state?
- Next.js: Data fetching, Updating data
- Facts checked November 24, 2026.