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