Client State Libraries: Zustand, Redux Toolkit and Jotai

Use a store library when global client state outgrows context: Zustand for simplicity, Redux Toolkit for large teams, Jotai for atoms.

Intermediate · about 5 hours · difficulty 3/5

Learn first: State Management Principles

Once you know what is truly global client state, a small library can manage it with less boilerplate and better performance than context.

Zustand (our default)

A tiny store created with a hook: const useCart = create((set) => ({ items: [], add: (i) => set((s) => ({ items: [...s.items, i] })) })). Components subscribe with selectors (useCart(s => s.items.length)) and re-render only when the selected slice changes. Middleware adds persistence (persist) and devtools. Minimal API, no providers.

Redux Toolkit

The modern, official way to write Redux. createSlice generates reducers and actions (with Immer letting you write "mutating" code safely), configureStore sets up devtools, and RTK Query handles server data. Redux shines in large apps and teams that value strict patterns, time-travel debugging and a single, predictable event log. Many existing codebases use it, so you should be able to read it.

Jotai

State as atoms: small independent pieces (const countAtom = atom(0)) combined into derived atoms. It fits apps with lots of fine-grained, interdependent state such as editors and canvases.

Others you may meet

MobX (observable, mutable style), Valtio (proxy state) and XState (state machines for complex flows, optional but powerful).

Pitfalls

Selecting the whole store (useStore()) so every change re-renders everything; putting server data in these stores instead of a server-state library; creating one giant store for unrelated concerns.

Good enough to move on

You can implement a persisted cart in Zustand with selectors, read and modify a Redux Toolkit slice in an existing codebase, and explain when you would reach for each tool.

Key concepts

  • Zustand stores and selectors
  • Zustand persist and devtools middleware
  • Redux Toolkit createSlice and configureStore
  • Redux DevTools
  • Jotai atoms and derived atoms
  • Selector-based re-render control
  • State machines with XState

Mini project

Build a shopping cart with Zustand (persisted to localStorage, selector-based badge count), then re-implement the same slice with Redux Toolkit and compare the amount of code and the devtools experience.

Check yourself

Why does `const store = useCartStore()` re-render a component more often than `useCartStore(s => s.count)`?

Free resources