Full answer
Most "we need Redux" problems are really "we mixed several kinds of state". Sorting them first removes most of the need for a global store.
Local state is used by one component or a small subtree: an open dropdown, an input value. Use useState or useReducer, and lift state only as far as needed.
Server state is a copy of data owned by a backend. It needs fetching, caching, refetching, deduplication, retries and invalidation after mutations. Writing that in effects and a global store is a lot of work. TanStack Query (or SWR, or the data layer of a framework) handles it, and removes most of the data from client stores.
URL state, such as filters, pagination and the selected tab, belongs in the address with the router's search params, which makes pages shareable and back-button friendly.
Form state with many fields and validation can use actions, or a library such as React Hook Form.
What remains is shared client state: a shopping cart, a multi-step wizard, a drawing tool's selection. For this, context works only if the data changes rarely, because every consumer re-renders. A store with selectors lets each component subscribe to a slice.
Zustand creates a store with one function, needs no provider and re-renders a component only when its selected value changes. Jotai uses small atoms for fine-grained updates. Redux Toolkit adds slices, immutable updates through Immer, middleware, strong devtools with time travel, and conventions that help large teams stay consistent. Its cost is more ceremony.
A reasonable default for a new product is useState, a query library and the router first, then add Zustand or Redux Toolkit when a real shared client state appears.
The store in the example uses selectors, so the component that shows the last action does not re-render when the same action repeats.
import { create } from 'zustand';
const useCartStore = create((set) => ({
items: [],
lastAction: 'none',
add: (name) =>
set((state) => ({ items: [...state.items, name], lastAction: 'add ' + name })),
clear: () => set({ items: [], lastAction: 'clear' }),
}));
function CartCount() {
const count = useCartStore((state) => state.items.length);
console.log('CartCount rendered');
return <p>Items: {count}</p>;
}
function LastAction() {
const lastAction = useCartStore((state) => state.lastAction);
console.log('LastAction rendered');
return <p>Last action: {lastAction}</p>;
}
function Controls() {
const add = useCartStore((state) => state.add);
const clear = useCartStore((state) => state.clear);
return (
<div>
<button onClick={() => add('pen')}>Add pen</button>
<button onClick={clear}>Clear</button>
</div>
);
}
export default function App() {
return (
<div>
<Controls />
<CartCount />
<LastAction />
</div>
);
}This example uses the zustand package. Each component selects only what it needs. The check added a pen twice and then cleared the cart. The second add does not change lastAction, so only CartCount rendered again for it. Console output (the first two lines are the mount): CartCount rendered LastAction rendered CartCount rendered LastAction rendered CartCount rendered CartCount rendered LastAction rendered
Key points
- Separate local, server, URL, form and shared client state before choosing a tool.
- A query library handles server data, so most data should not live in a client store.
- Context is for low-frequency values. Fast-changing shared state needs a store with selectors.
- Zustand is small and flexible. Redux Toolkit gives structure, middleware and devtools for larger teams.
- Start simple and add a store only when a real shared client state exists.
Common mistakes
- Putting server data into a client store and rewriting caching by hand.
- Putting every value in a global store, including local form inputs.
- Selecting the whole store in a component, which re-renders on any change.
- Selecting a new object or array in a selector without equality handling.
- Choosing Redux or Zustand from habit instead of from the kind of state.
Follow-ups
- What does TanStack Query give you that a Redux store does not?
- How would you persist part of a Zustand store to local storage?
- How do Server Components change where data fetching and state live?
Tips
- Begin with the classification of state. It shows a framework for thinking, not tool loyalty.
- Name one criterion for each tool. Do not just list libraries.
- State the default stack for a new project and when you would add a store.