Context vs Redux?
Context is React's built-in way to pass a value down the tree; it does not manage state or optimize updates, and every consumer re-renders when the value changes. Redux (today, Redux Toolkit) is a state management library with a central store, reducers, middleware, selective subscriptions and DevTools. Use Context for low-frequency shared values and Redux for large, frequently changing, complex app state.
Comparison
| Context (+ useState/useReducer) | Redux Toolkit | |
|---|---|---|
| Install | built in | @reduxjs/toolkit, react-redux |
| Purpose | dependency injection of a value | predictable global state management |
| Re-renders | all consumers on any value change | only components whose selected slice changed |
| Middleware, side effects | none built in | thunks, listener middleware, RTK Query |
| DevTools | React DevTools only | Redux DevTools with time-travel and action log |
| Boilerplate | low | moderate (much less than classic Redux) |
| Server data caching | no | RTK Query |
When Context is enough
Theme, locale, auth user, feature flags, small apps, and component-library internals.
When Redux shines
- Large teams wanting strict, consistent patterns.
- Complex state transitions with many actions.
- Need for action history, debugging and time-travel.
- Existing Redux codebases.
Other options in between
Zustand and Jotai offer store-like selective subscriptions with very little boilerplate. For server data, TanStack Query or RTK Query rather than either Context or plain Redux.
Interview answer
"They solve different problems; Context transports values, Redux manages state. I pick based on update frequency, app size and team needs."
Code example
1// Redux Toolkit store with selective subscriptions2import { configureStore, createSlice, type PayloadAction } from "@reduxjs/toolkit";3import { Provider, useDispatch, useSelector } from "react-redux";45const cartSlice = createSlice({6 name: "cart",7 initialState: { items: [] as { id: string; qty: number }[] },8 reducers: {9 added(state, action: PayloadAction<string>) {10 const item = state.items.find((i) => i.id === action.payload);11 item ? item.qty++ : state.items.push({ id: action.payload, qty: 1 }); // Immer makes this immutable12 },13 },14});1516const store = configureStore({ reducer: { cart: cartSlice.reducer } });17type RootState = ReturnType<typeof store.getState>;1819function CartCount() {20 // Re-renders only when the count changes, not on every store update21 const count = useSelector((s: RootState) => s.cart.items.reduce((n, i) => n + i.qty, 0));22 return <span>{count}</span>;23}2425function AddButton({ id }: { id: string }) {26 const dispatch = useDispatch();27 return <button onClick={() => dispatch(cartSlice.actions.added(id))}>Add</button>;28}2930export const App = () => <Provider store={store}><CartCount /><AddButton id="pen" /></Provider>;
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.