Redux Toolkit vs Zustand vs Context: how do you manage client state?
First, classify the state
- Server state (from APIs) → TanStack Query / RTK Query / SWR.
- URL state (filters, page, selected tab) → the router's search params.
- Form state → React Hook Form.
- Local UI state →
useState/useReducerin the component. - What remains is global client state: auth session, cart, theme, feature flags, wizard progress.
Context
Built in; good for values that change rarely (theme, locale, current user). Every consumer re-renders when the value changes, so it is not a high-frequency store.
Redux Toolkit (RTK)
The official, modern Redux: configureStore, createSlice (reducers with Immer, so "mutating" code is safe), createAsyncThunk, and RTK Query for data fetching. Strong conventions, excellent DevTools (time travel), middleware, predictable updates. Best for large teams and complex state transitions.
Zustand
A tiny store: create((set, get) => ({ ... })), no provider, select slices with a hook so components re-render only when their slice changes. Little boilerplate, middleware for persistence and DevTools. Best for small to medium apps.
Jotai / Recoil-style atoms
Bottom-up atomic state; fine-grained updates for highly interactive UIs (editors, canvases).
Example
// Redux Toolkit slice
import { createSlice, configureStore, type PayloadAction } from '@reduxjs/toolkit';
type Item = { id: string; price: number; qty: number };
const cartSlice = createSlice({
name: 'cart',
initialState: { items: [] as Item[] },
reducers: {
added(state, action: PayloadAction<Omit<Item, 'qty'>>) {
const line = state.items.find(i => i.id === action.payload.id);
line ? line.qty++ : state.items.push({ ...action.payload, qty: 1 }); // Immer makes this immutable
},
removed(state, action: PayloadAction<string>) {
state.items = state.items.filter(i => i.id !== action.payload);
},
},
});
export const { added, removed } = cartSlice.actions;
export const store = configureStore({ reducer: { cart: cartSlice.reducer } });
export type RootState = ReturnType<typeof store.getState>;// The same with Zustand (+ persistence)
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
export const useCart = create<{ items: Item[]; add(i: Omit<Item, 'qty'>): void }>()(
persist(
set => ({
items: [],
add: i => set(s => {
const line = s.items.find(x => x.id === i.id);
return { items: line ? s.items.map(x => (x.id === i.id ? { ...x, qty: x.qty + 1 } : x)) : [...s.items, { ...i, qty: 1 }] };
}),
}),
{ name: 'cart' },
),
);
// const count = useCart(s => s.items.length); // re-renders only when the count changesFollow-up questions interviewers ask
Try answering each one before you open it.
Why do selectors matter for performance?
A component that subscribes to the whole store re-renders on every change. Selecting only the needed slice (useSelector(s => s.cart.items.length) or useCart(s => s.total)) means React re-renders it only when that value changes. Memoised selectors (createSelector) avoid recomputing derived data.