← All topics

State Management Senior interview questions and answers

75 questions for a State Management (Senior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.Why do Redux, Zustand and similar libraries subscribe through useSyncExternalStore?
  2. 2.What's wrong with this getSnapshot?
  3. 3.What's the difference between the "subscribe to a selector" model (Redux, Zustand) and Context?
  4. 4.Where should the state of a list filter (search text, sort, page) ideally live in a routed app?
  5. 5.Which classification of state helps pick tools in a large app?
  6. 6.How do you prevent consumers of a CartContext from re-rendering when only dispatch-style actions are used?
  7. 7.Why are Context providers in the Next.js App Router placed in a separate client component?
  8. 8.Why is "one big AppContext with all state" considered an anti-pattern?
  9. 9.What does use(Context) in React 19 add compared to useContext?
  10. 10.What is createListenerMiddleware for?
  11. 11.What does combineSlices add to Redux Toolkit?
  12. 12.Why shouldn't you put promises, class instances or functions into the Redux store?
  13. 13.What does a memoized selector from createSelector need to be effective with arguments?
  14. 14.Why does Redux recommend the "ducks"/feature-folder structure with createSlice?
  15. 15.A reducer for orders/placed must also clear the cart slice. What's the idiomatic way?
  16. 16.Why is a module-level Zustand store dangerous in SSR (Next.js)?
  17. 17.How do you persist only some fields of a Zustand store and handle schema changes?
  18. 18.How do you react to Zustand changes outside React (e.g. sync to an analytics SDK)?
  19. 19.What does the devtools middleware give a Zustand store?
  20. 20.Zustand vs Redux Toolkit: when is RTK the stronger choice?
  21. 21.How do you implement an optimistic update with the cache in TanStack Query?
  22. 22.What is structural sharing in TanStack Query?
  23. 23.Why are query key factories recommended?
  24. 24.How do you pass server-prefetched TanStack Query data to client components in the Next.js App Router?
  25. 25.Why must you not create one global QueryClient for all requests on the server?
  26. 26.What does useSuspenseQuery change?
  27. 27.What must you configure for useInfiniteQuery?
  28. 28.How do you cancel an in-flight request when a query becomes unused in TanStack Query?
  29. 29.What does the select option of useQuery give you?
  30. 30.How do you do an optimistic update in RTK Query?
  31. 31.How does RTK Query decide which tagged queries to refetch with id-level tags?
  32. 32.What is transformResponse used for in an RTK Query endpoint?
  33. 33.How do you write the result of a mutation directly into a cached query without refetching (pessimistic update)?
  34. 34.Can RTK Query and createSlice state coexist in one store?
  35. 35.How do you make an optimistic update with SWR's mutate?
  36. 36.What does useSWRMutation give compared to calling fetch and then mutate?
  37. 37.How does SWR avoid re-rendering a component when unrelated fields of the response change?
  38. 38.How do you pass server-fetched data to SWR so the first client render has it?
  39. 39.SWR vs TanStack Query: what's a fair summary?
  40. 40.Why are route loaders said to remove "request waterfalls" compared with useEffect fetching?
  41. 41.How do you prevent a loader from re-running after every action on the page?
  42. 42.How do you build optimistic UI with a React Router fetcher?
  43. 43.How do you stream slow, non-critical data from a React Router loader?
  44. 44.Do you still need a client cache library (TanStack Query) with React Router loaders?
  45. 45.How should validation errors from a React Router action reach the form?
  46. 46.A legacy app keeps API responses in Redux slices with hand-written loading flags. What's a pragmatic migration?
  47. 47.How do you keep two browser tabs' client state in sync (e.g. logout in one tab)?
  48. 48.What's the main risk of copying server data from useQuery into a Zustand/Redux store?
  49. 49.Which approach makes state logic easiest to unit-test regardless of the library?
  50. 50.When is a finite state machine (e.g. XState) a better model than a reducer with flags?
  51. 51.How do you push WebSocket updates into an RTK Query cache entry?
  52. 52.How do you implement infinite scrolling with a single RTK Query cache entry?
  53. 53.What does persisting the TanStack Query cache (persistQueryClient) give you, and what must you watch out for?
  54. 54.What happens to TanStack Query requests when the browser goes offline (default networkMode: 'online')?
  55. 55.What is wrong with this cache update?
  56. 56.How should components using TanStack Query be set up in tests?
  57. 57.How do you give each instance of a complex widget its own Zustand store?
  58. 58.How do you react to very frequent Zustand changes (e.g. pointer position at 60fps) without re-rendering?
  59. 59.What is an efficient way to implement undo/redo for a large document state?
  60. 60.Why validate state read from the URL (search params) with a schema?
  61. 61.Why send an idempotency key with an optimistic "create order" request that may be retried?
  62. 62.How do you show a global indicator for all in-flight React Router fetchers (e.g. several "like" buttons)?
  63. 63.What does SWR's custom cache provider option allow?
  64. 64.With React Server Components fetching data on the server, what typically changes about client-side state libraries?
  65. 65.Why does React Redux implement useSelector on top of useSyncExternalStoreWithSelector?
  66. 66.How should independently deployed micro-frontends share state like the current user?
  67. 67.When does useSelector(selector, shallowEqual) help?
  68. 68.Which approach suits collaborative editing where several users change the same document offline and online?
  69. 69.How do you update an edited todo in every cached list (filtered views) at once?
  70. 70.Why can dependent queries create a waterfall, and how do you reduce it?
  71. 71.How does staleTime: Infinity differ from refetchOnMount: false?
  72. 72.When is an event bus better than shared state for cross-feature communication?
  73. 73.Why model async state as a discriminated union instead of separate fields?
  74. 74.What's wrong with providesTags: (result) => result.map(({ id }) => ({ type: "Post", id }))?
  75. 75.Where should an unsaved long form draft live so it survives a reload or crash?