State Management Junior interview questions and answers
75 questions for a State Management (Junior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.What is "state" in a React component?
- 2.Why doesn't the counter on screen change?
- 3.When should you use the functional update
setCount(c => c + 1)instead ofsetCount(count + 1)? - 4.What's the right way to update one field of an object in state?
- 5.How do you remove an item with
idfrom an array in state? - 6.Why pass a function to
useState(() => createInitialTodos())? - 7.Should you store
fullNamein state if you already havefirstNameandlastName? - 8.What is "local" (component) state and when is it enough?
- 9.What does
useReducerreturn? - 10.What must a reducer function be like?
- 11.When is
useReducerusually a better choice than severaluseStatecalls? - 12.What does a reducer usually return for an unknown action
type? - 13.Why name actions after what happened (
'task_added') rather than what to do ('set_tasks')? - 14.What is prop drilling?
- 15.What is "lifting state up"?
- 16.Which technique often solves prop drilling without Context?
- 17.Is passing props down 2–3 levels a problem by itself?
- 18.What problem does the Context API solve?
- 19.What are the steps to use Context?
- 20.What does
useContext(ThemeContext)return if there's no provider above? - 21.Which components re-render when a provider's
valuechanges? - 22.Which data is a good fit for Context?
- 23.Why wrap
useContextin a custom hook likeuseAuth()? - 24.Can a component use several contexts at once?
- 25.What is Redux Toolkit (RTK)?
- 26.What does
createSlicegenerate? - 27.Why can you "mutate"
stateinsidecreateSlicereducers? - 28.What does
configureStoredo? - 29.How do you connect a Redux store to a React app?
- 30.What are
useSelectoranduseDispatchfor? - 31.What is an action in Redux?
- 32.Where should a request to the server live in Redux Toolkit?
- 33.What is Zustand?
- 34.How do you read just one field from a Zustand store?
- 35.How do you update state in Zustand?
- 36.Does a Zustand store require a Provider component?
- 37.How do you save a Zustand store to
localStorage? - 38.How does server state differ from client (UI) state?
- 39.What is TanStack Query (React Query) for?
- 40.What are the two required parts of
useQuery? - 41.What's needed before calling
useQueryin an app? - 42.How do you send a POST request (create an item) with TanStack Query?
- 43.Why does TanStack Query refetch data when you return to the browser tab?
- 44.What is RTK Query?
- 45.What does
createApigenerate for an endpointgetPosts: builder.query(...)? - 46.How does an RTK Query mutation make lists refetch after adding an item?
- 47.What does the name SWR stand for?
- 48.What are the arguments of
useSWR(key, fetcher)? - 49.What is a
loaderin React Router? - 50.What is an
actionin React Router? - 51.Does changing the argument of
useState(initial)on later renders update the state? - 52.When should two pieces of state be combined into one object?
- 53.Where should a Context provider be placed?
- 54.Which three principles describe classic Redux?
- 55.What do the Redux DevTools let you do?
- 56.Why define selector functions like
selectCartTotal(state)instead of inline lookups everywhere? - 57.Where does the argument go when you dispatch
todoAdded("Buy milk")created bycreateSlice? - 58.What does a Redux store object provide?
- 59.What is
createAsyncThunkfor? - 60.How does a Zustand action read the current state?
- 61.Why can Zustand cause fewer re-renders than a single Context for the same state?
- 62.Which fields of a
useQueryresult do you usually render from? - 63.How do you manually refetch a query, e.g. from a "Refresh" button?
- 64.What do the TanStack Query Devtools show?
- 65.Which hooks does RTK Query generate for
getPosts(query) andaddPost(mutation) endpoints? - 66.How does
isLoadingdiffer fromisValidatingin SWR? - 67.Why should an SWR fetcher throw on non-OK HTTP responses?
- 68.How do you read the
:idpart of the URL/users/:idin a React Router component? - 69.How does a React Router loader know which item to load?
- 70.Where should a search box's query live so the page can be shared and survives reload?
- 71.A small app has a theme switch and a logged-in user. Which state tools are usually enough?
- 72.What is a "store" in state management libraries?
- 73.How can a component remember a setting in
localStoragebetween visits? - 74.What does a typical action object for
useReducerlook like? - 75.What is the "atomic" state approach of libraries like Jotai?