React Context vs Redux vs Zustand — Which Should You Use?
The Interview Question
When would you use React Context vs. a state management library like Redux or Zustand?
Expert Answer
React Context is not a state management tool — it's a dependency injection mechanism. This distinction matters. Context lets you pass values down the tree without prop drilling, but it has a fundamental performance characteristic: when a context value changes, every component that consumes that context re-renders, regardless of whether they use the specific piece of data that changed. For low-frequency updates (theme, locale, auth status), Context is perfect. For high-frequency updates (form state, real-time data, complex UI state), Context causes unnecessary re-renders at scale. Redux solves this with selectors — components only re-render when the specific slice of state they select changes. Zustand offers the same selective re-rendering with far less boilerplate. The practical rule: if you're reaching for Context and adding useMemo everywhere to prevent re-renders, you've outgrown Context and need a state management library.
Key Points to Hit in Your Answer
- Context is dependency injection, not state management
- Context re-renders ALL consumers when any value changes
- Redux/Zustand use selectors for granular re-renders
- Context is ideal for: themes, auth, locale — things that change rarely
- Redux is ideal for: complex state logic, middleware, time-travel debugging
- Zustand is ideal for: simple global state with good performance and minimal boilerplate
Code Example
// Context — every consumer re-renders on ANY change
const AppContext = createContext();
// If user OR theme changes, BOTH consumers re-render
<AppContext.Provider value={{ user, theme }}>
<UserDisplay /> {/* re-renders on theme change too */}
<ThemeToggle /> {/* re-renders on user change too */}
</AppContext.Provider>
// Zustand — only re-renders on selected state
const useStore = create((set) => ({
user: null,
theme: 'dark',
setTheme: (t) => set({ theme: t }),
}));
// Only re-renders when theme changes
const theme = useStore((state) => state.theme);
What Interviewers Are Really Looking For
Senior-level question. The key insight is articulating that Context is not state management. Interviewers want to hear about the re-render problem and how selectors solve it. Mentioning specific tradeoffs between Redux (powerful but verbose) and Zustand (simple but less ecosystem) shows real-world experience.
Practice This Question with AI Grading
Reading about interview questions is a start — but practicing with real-time AI feedback is how you actually get better. Goliath Prep grades your answers instantly and tells you exactly what you're missing.
Start Practicing Free →