Command Palette

Search for a command to run...

Hectal
Phase 15Advanced16 of 28 in React

State Management at Scale

Sort state into its kinds, see where context stops scaling, and learn Zustand, Redux Toolkit, atoms, signals and state machines, and how to choose between them.

Small apps keep state in useState, lift it up, and pass it down, with context for the few values everybody needs. As an app grows, three problems appear: one context change re-renders half the screen, data from the server gets copied into state and goes stale, and nobody can say where a value lives. This phase fixes all three.

You'll first sort state into its kinds (UI, form, server, URL and global client state) and give each kind its proper home. Then you'll measure why a big context re-renders too much and build the fix yourself: an external store read with useSyncExternalStore and a selector. Every library in this phase is that same idea, polished: Zustand, Redux Toolkit, atoms (Jotai), signals, MobX and state machines (XState).

Every live example logs its renders, so you can count re-renders with your own eyes instead of trusting a benchmark. The last topic is a decision guide: which tool for which job, how TanStack Query and a small client store share the work, and how to migrate a real app one piece at a time.

0/6 · 0%
6 topics ~3 h 21 code blocks & diagrams
Start with the first topic
1
15.1

Kinds of State and Where Each Belongs

Not all state is the same: UI state, form state, server state, URL state and global client state each change for different reasons and each has a best home, so picking the right tool starts with naming the kind.

26 min 1 diagram 2 code practice

2
15.2

When Context Isn't Enough

Every component that reads a context re-renders whenever the context value changes, even if it uses only one small part of it; splitting contexts helps, and an external store read through useSyncExternalStore with a selector fixes it properly.

28 min 1 diagram 3 code practice

3
15.3

Zustand

Zustand is a tiny external store library: create makes a hook that holds state and actions together, components read slices with selectors and re-render only when their slice changes, and middleware adds saving to localStorage and Redux DevTools.

28 min 4 code practice

4
15.4

Redux with Redux Toolkit

Redux keeps app state in one store that changes only when you dispatch an action, which a pure reducer turns into the next state; Redux Toolkit is the official, modern way to write it, with slices, Immer, thunks, memoised selectors and RTK Query.

29 min 4 code practice

5
15.5

Atoms, Signals and Other Models

Besides one big store, state can be split into tiny independent atoms (Jotai, Recoil), tracked automatically with signals or observables (Preact Signals, MobX), or modelled as a state machine (XState); each model trades React's simple re-render rule for a different kind of precision.

29 min 3 code practice

6
15.6

Choosing a State Tool

Choose by the kind of state, not by fashion: local state and the URL first, a query cache for server data, context for rare global values, and a small store (Zustand, Redux Toolkit, Jotai) only for busy global client state, introduced and migrated one feature at a time.

26 min 3 code practice

Practise this phase

Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.