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