State Management Interview Questions and Answers
useState and useReducer, prop drilling, Context, Redux Toolkit, Zustand, and server state with TanStack Query, RTK Query, SWR and React Router loaders/actions.
225 questions for State Management interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- useState
- useReducer
- Context
- Redux Toolkit
- Zustand
- TanStack Query
- RTK Query
- SWR
- React Router
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
State Management · Junior
- What is "state" in a React component?
Correct answer: Data that changes over time and affects what's on screen; a change triggers a re-render
State is the component's memory between renders: a counter value, form input, whether a menu is open. A regular
letvariable resets on every render and its change doesn't tell React to update the UI. Props are read-only inputs owned by the parent. - When should you use the functional update
setCount(c => c + 1)instead ofsetCount(count + 1)?Correct answer: When the new value depends on the previous one, especially with several updates in a row
countis a snapshot of the current render. ThreesetCount(count + 1)calls in one handler produce +1, while threesetCount(c => c + 1)produce +3, because each updater receives the result of the previous one. It also protects against stale closures in timers and effects. - How do you remove an item with
idfrom an array in state?Correct answer:
setItems(items.filter(i => i.id !== id))State must be updated immutably:
filter,map, spread andtoSortedcreate a new array.spliceanddeletemutate the existing one, the reference stays the same, and React skips the update. - Why pass a function to
useState(() => createInitialTodos())?Correct answer: So the expensive computation runs only on the first render
useState(createInitialTodos())calls the function on every render, even though the result is used only once. A lazy initializeruseState(createInitialTodos)is called only on mount. It must be synchronous and pure.
State Management · Middle
- How do you reset a form component's state when the selected user changes?
Correct answer: Render it with
key={userId}so React recreates the componentA different
keymakes React treat it as a new component: old state is dropped and the initial values apply. A resetting effect first renders stale data and then fixes it - an extra render and a visible flash. - How do you pass
dispatchfromuseReducerdeep into the tree without prop drilling?Correct answer: Put
dispatchinto its own context; it never changes, so consumers don't re-renderThe "reducer + context" pattern: one context for
state, another fordispatch. Components that only send actions (buttons, forms) read the stable dispatch context and don't re-render when the state changes. - What's the purpose of the third argument
initinuseReducer(reducer, arg, init)?Correct answer: Lazy initialization:
init(arg)is called only on the first renderuseReducer(reducer, username, createInitialState)avoids recomputing an expensive initial state on every render - like a lazy initializer inuseState.initcan also be reused to reset the state. - A component uses only
themefrom a bigAppContextbut re-renders on every cart update. What helps?Correct answer: Split the context into smaller ones by domain and change frequency
React.memodoesn't stop re-renders caused by a context the component reads. SeparateThemeContextandCartContextlimit updates to the consumers that need them. For very frequent updates, use a store with selectors.
State Management · Senior
- Why do Redux, Zustand and similar libraries subscribe through
useSyncExternalStore?Correct answer: It guarantees a consistent snapshot during concurrent rendering (no tearing)
With concurrent rendering React may pause a render; if an external store changes meanwhile, some components could read old values and others new ones.
useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)prevents that and supports SSR. - What's the difference between the "subscribe to a selector" model (Redux, Zustand) and Context?
Correct answer: A store notifies components and each re-renders only if its selected slice changed
Context has no selectors: any
valuechange re-renders every consumer. Stores run each subscriber's selector and compare results, so updates are fine-grained. Libraries likeuse-context-selectoremulate this on top of Context. - Where should the state of a list filter (search text, sort, page) ideally live in a routed app?
Correct answer: In the URL search params - shareable, survives reloads and works with back/forward
The URL is state too. Filters in
?q=&sort=&page=make links shareable and history meaningful, and loaders/query keys can derive from them. Debounce typing and replace (not push) history entries for every keystroke. - Which classification of state helps pick tools in a large app?
Correct answer: Server cache, URL state, form state, local UI state and global client state
Each kind has a natural home: server cache - TanStack Query/RTK Query/SWR/loaders; URL - the router; forms - local state or a form library; UI -
useState; truly global client state - Context or a store. Putting everything into one store makes it the bottleneck.
Combined quizzes with this topic
Questions from several topics at once - just like an interview for a specific role.
Coding tasks
Write your solution right in the browser, and tests check it instantly. Interview classics: debounce, throttle, deepClone, Promise.all, EventEmitter, an LRU cache and more.
Open tasks →