BugCast
React

State Management: When to Use What

Local state, Context, Zustand, Redux — pick the right tool and explain why.

BugCast Admin··8 min read

Decision Framework

NeedSolution
Component-only UI stateuseState / useReducer
Shared state, few consumersLift state up
Deep tree, moderate sharingContext
Complex global stateZustand / Redux / Jotai
Server stateTanStack Query / SWR

Context Pitfalls

// Every consumer re-renders when ANY context value changes
const ThemeContext = createContext();

// Fix: split contexts or memoize values
const value = useMemo(() => ({ theme, toggle }), [theme]);

Interview Questions

Q: When is Redux overkill?

Small apps, mostly server-fetched data, or simple UI state. Prefer React Query + local state.

Q: useReducer vs useState?

useReducer for complex state transitions, multiple sub-values, or when next state depends on previous.

Q: How does Zustand differ from Redux?

Minimal boilerplate, no providers required, direct store access, built-in selectors. Redux offers stronger devtools and middleware ecosystem.

#state#redux#zustand#interview

Related posts