Part 16 / Topic 7 of 9
Decision-tree note: when useContext/useReducer stop being enough
This section is a survey, not a lesson - no new package was installed or run to write it, the same honesty stage-5-specialization/track-state-management-ecosystems.md states about its own brief. Part 9 and Part 10 already taught useReducer + useContext as, in this course's own words, "the poor man's Redux" - and for a genuinely large share of real apps, that pair never needs replacing. The signals worth naming, the ones that actually mean it's time to look further:
| Signal | What it looks like | What it means |
|---|---|---|
| One provider, one feature | A single context holds one coherent slice of state (one list, one small set of actions) | useReducer + useContext is still the right tool - this is Section 4's row 3, nothing more needed |
| Several unrelated features sharing one provider, or several providers nested just to avoid that | Cart state, user profile, a live subscription, and a multi-step form all crammed into one reducer's switch, or stacked as four nested <Provider>s wrapping the app |
A "provider pyramid" or an overloaded reducer are both signs the coordination problem has outgrown this pattern - a library built for many independent, deeply-consumed stores (Zustand's separate stores, Redux Toolkit's slices) solves the shape directly instead of nesting around it |
| A context value changing on every keystroke, with many unrelated consumers re-rendering on each change | A search box's text lives in the same context as data a dozen other components read, and all of them re-render on every keystroke even though only the search box's own consumer actually needed to | useContext has no built-in way to subscribe to only a slice of a context's value - every consumer re-renders on any change to it. Splitting the context is the first, no-new-dependency fix; a library with built-in selector-style subscriptions is the answer if this keeps recurring across many different pieces of state, not just one |
Named here, not taught here: Zustand and Redux Toolkit are the two libraries this decision tree points toward once one of the signals above shows up for real. This course deliberately stops at naming them - the same pattern DESIGN-NOTES.md's "State-management libraries: surveyed, not taught, in the core track" section describes for exactly this part, and the same pattern the course already used for raw fetch (Part 11) before a data-fetching library gets its own lesson. Hands-on depth on either library, installed and run for real, is Stage 5's "State management ecosystems" track's job - it rebuilds this course's own Stage 4 capstone's state layer on one of them, side by side with the hand-rolled version, specifically so the comparison is concrete instead of theoretical.
Done here? The practice set for Part 16 — including the solutions — is on the part page.