← All topics

State Management Middle interview questions and answers

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

Take this quiz
  1. 1.What will count be after one click if it starts at 0?
  2. 2.How do you reset a form component's state when the selected user changes?
  3. 3.Why can storing a copy of a prop in state be a bug?
  4. 4.How do you pass dispatch from useReducer deep into the tree without prop drilling?
  5. 5.What's the purpose of the third argument init in useReducer(reducer, arg, init)?
  6. 6.Why do all context consumers re-render on every provider render?
  7. 7.A component uses only theme from a big AppContext but re-renders on every cart update. What helps?
  8. 8.Why doesn't React.memo help a component that calls useContext(CartContext)?
  9. 9.Is Context a state management library?
  10. 10.What happens with nested providers of the same context?
  11. 11.When is it better to put a value in Context instead of passing it explicitly through props?
  12. 12.What's wrong with this case reducer?
  13. 13.Which actions does createAsyncThunk('users/fetch', fn) dispatch?
  14. 14.Why does this selector re-render the component on every dispatched action?
  15. 15.What is extraReducers in createSlice for?
  16. 16.How do you type useSelector and useDispatch in a TypeScript project?
  17. 17.What does normalized state ({ ids, entities }) give you?
  18. 18.What does configureStore check in development mode?
  19. 19.Should form input state (each keystroke) go into Redux?
  20. 20.Why does this component re-render on every store change?
  21. 21.Why does a selector returning a new object cause extra re-renders (or a loop in v5)?
  22. 22.How do you read or update a Zustand store outside React components (e.g. in an API helper)?
  23. 23.How does set in Zustand handle nested objects?
  24. 24.How is a large Zustand store usually organized?
  25. 25.Why can a persist-ed store cause a hydration mismatch in SSR apps?
  26. 26.How does staleTime differ from gcTime?
  27. 27.How does isPending differ from isFetching?
  28. 28.How do you refresh the list after useMutation creates an item?
  29. 29.Which queries does invalidateQueries({ queryKey: ['todos'] }) match?
  30. 30.How do you run a query only after another one returned user.id?
  31. 31.With pagination, how do you keep showing the previous page while the next one loads?
  32. 32.What does TanStack Query do on a failed query by default?
  33. 33.Why should every variable the queryFn uses be part of the queryKey?
  34. 34.How do you make an RTK Query mutation refetch the post list?
  35. 35.When does RTK Query remove unused data from its cache?
  36. 36.How do you skip an RTK Query request until an argument is available?
  37. 37.How does RTK Query avoid duplicate requests when 3 components call useGetUserQuery(1)?
  38. 38.What does the refetchOnMountOrArgChange option do in RTK Query?
  39. 39.When does SWR revalidate data automatically by default?
  40. 40.How do you fetch data in SWR only when a condition is met?
  41. 41.What does mutate(key) from useSWRConfig do?
  42. 42.Why do two components with the same SWR key make only one request?
  43. 43.How do you set a default fetcher and options for all SWR hooks?
  44. 44.How does a component read the data returned by its route loader?
  45. 45.What happens after a React Router action completes?
  46. 46.How do you show a pending state during navigation or form submission in React Router?
  47. 47.When should you use useFetcher instead of <Form>?
  48. 48.How do you redirect from an action after creating an item?
  49. 49.Server data is in TanStack Query. What's usually left for a global client store?
  50. 50.How does RTK Query compare to TanStack Query?
  51. 51.What is the prepare callback in a createSlice reducer for?
  52. 52.How do you handle the pending state of many thunks with one case in a slice?
  53. 53.Should you store cartTotal in the Redux state next to items?
  54. 54.How do you skip a thunk if the data is already loaded or loading?
  55. 55.How does a component get the thunk's result or catch its error?
  56. 56.How do you add RTK Query endpoints from a lazily loaded feature?
  57. 57.How do you refetch an RTK Query every 30 seconds while the component is mounted?
  58. 58.How do you make a component re-render only when one post from a cached list changes?
  59. 59.What does the second argument true do in Zustand's set(newState, true)?
  60. 60.Why do some teams group Zustand actions into a nested actions object?
  61. 61.How does initialData differ from placeholderData in TanStack Query?
  62. 62.What does the queryOptions helper give you?
  63. 63.How do you poll a query every 10 seconds with TanStack Query?
  64. 64.How does mutateAsync differ from mutate?
  65. 65.How do you fetch a dynamic number of queries in parallel (e.g. one per selected id)?
  66. 66.How can you make opening a detail page feel instant?
  67. 67.Which SWR hook implements "load more" pagination?
  68. 68.How do you start an SWR request before the component renders (e.g. on hover)?
  69. 69.What does keepPreviousData: true do in SWR when the key changes (e.g. a new search query)?
  70. 70.What happens when a React Router loader throws?
  71. 71.What is clientLoader in React Router framework mode?
  72. 72.Why update search params with { replace: true } while the user types a filter?
  73. 73.What is the difference between optimistic and pessimistic updates?
  74. 74.How can a header badge show all pending "add to cart" mutations from other components?
  75. 75.How do you integrate a WebSocket price feed into SWR's cache?