First classify the state, then pick the simplest tool that fits:
useState/useReducer in the component that uses it, lifted only as far as needed.| Question | If yes |
|---|---|
| Does it come from the server? | Query cache / loaders |
| Should it be in the URL (shareable, back button)? | Search params |
| Used by one component or a small subtree? | useState/useReducer, colocated |
| Shared widely but changes rarely? | Context |
| Shared widely and changes often, or consumers need slices? | External store with selectors |
| Complex transitions, impossible states? | Reducer or state machine |
| Must persist (localStorage, IndexedDB) or sync across tabs? | Store with persistence middleware |
Context has no selectors: every consumer re-renders on any value change. It's ideal for dependency injection and rarely changing values, and poor for hot state like cursor positions, form field values in large forms, or collaborative documents. Splitting contexts helps up to a point. After that, useSyncExternalStore-based stores let components subscribe to exactly the slice they need.
Putting server data in a global store means hand-writing caching, invalidation, loading flags and deduplication, which query libraries do better. Putting local UI state there adds indirection and makes components less reusable. Use a global store for genuinely global, client-owned state.
// URL
const [params, setParams] = useSearchParams(); // ?status=open&page=2
// Server
const { data: tickets } = useQuery({ queryKey: ['tickets', params.toString()], queryFn: … });
// Local
const [isBulkEditOpen, setBulkEditOpen] = useState(false);
// Context
const { user, permissions } = useSession();
// Store (Zustand) for a complex cross-panel selection
const selectedIds = useSelectionStore(s => s.selectedIds);
Spotted a mistake or a rights concern? Report an issue