I have used Redux on every job since 2022, and I still do not put everything in it. Most state problems that I see in code reviews are not Redux problems or Context problems. The state is in the wrong place.
These are the questions I ask, in order. I stop at the first “yes”.
1. Can I compute it instead?
If a value comes from other state or props, do not store it. Compute it during render.
// Two sources of truth. One day they will not match.
const [items, setItems] = useState([]);
const [total, setTotal] = useState(0);
// One source of truth
const [items, setItems] = useState([]);
const total = items.reduce((sum, item) => sum + item.price * item.qty, 0);
If the calculation is slow, wrap it in useMemo. It is rarely slow.
2. Does only one component use it?
Then it is useState in that component: form inputs, an open dropdown, the active tab. Keep it there.
3. Do a few nearby components share it?
Lift it to their closest common parent and pass it down as props. Props through two or three levels are fine, and easy to follow.
4. Does it belong in the URL?
Filters, search text, the page number. If a user can bookmark the screen, refresh it, or send it to a colleague, the state belongs in the URL. React Router keeps this short:
const [params, setParams] = useSearchParams();
const status = params.get("status") ?? "all";
// later, in an event handler
setParams({ status: "shipped" });
5. Is it data from the server?
A list of orders is not app state. It is a copy of the server's data, and it gets old. It needs loading and error states, a cache, and a refetch. Use a tool built for that: RTK Query if the app already uses Redux Toolkit, or TanStack Query. A loading-and-error reducer written by hand for each endpoint is how a Redux store gets big.
6. Does the whole app need it, and does it rarely change?
The theme, the signed-in user, the language. This is what Context is for. Every component that reads a context renders again when its value changes, so Context suits values that change rarely.
7. Is it shared, does it change often, and does it have rules?
A cart, a multi-step form with validation, a dashboard where many widgets follow the same filters. Here Redux earns its place: one store, actions with names, and DevTools that show what changed and why. With Redux Toolkit, a slice is short:
import { createSlice } from "@reduxjs/toolkit";
const cartSlice = createSlice({
name: "cart",
initialState: { items: [] },
reducers: {
added(state, action) {
const item = state.items.find((i) => i.id === action.payload.id);
if (item) item.qty += 1;
else state.items.push({ ...action.payload, qty: 1 });
},
removed(state, action) {
state.items = state.items.filter((i) => i.id !== action.payload);
},
},
});
export const { added, removed } = cartSlice.actions;
export default cartSlice.reducer;
The code changes state directly, and that is safe here: Redux Toolkit uses Immer, which turns the changes into a new object.
Select small pieces, so that a component renders again only when its piece changes:
const count = useSelector((state) => state.cart.items.length);
The short version
- Compute it if you can.
- Keep it local until two components need it.
- Put shareable screen state in the URL.
- Let a data-fetching library own server data.
- Use Context for app-wide values that rarely change.
- Use Redux for shared state that changes often and has rules.