Skip to content
Tech Interview Prep
Technical interview guideNew

React State Management

Where React state should live and which tool should own it: local state, lifting, Context, Redux Toolkit, Zustand, and the server-state libraries that replace hand-rolled caches. Covers the trade-offs interviewers use to separate people who have shipped a large React app from people who have only read about one.

Read
14 min
Practice MCQs
25
Interview Q&A
25
Edition
v1
Editorial status
Reviewed
Relevant for
Frontend Engineer

Scope: React 19 and 18, Redux Toolkit 2.x, Zustand 5.x, TanStack Query 5.x, React Router 7, Next.js 15 — checked against current docs as of early 2025..

Curated: · Written: · Reviewed:

25 questions

MCQ-4A cart screen reads its list with `useSelector(state => state.items)` from a plain Redux store (no Redux Toolkit), and the reducer handles `items/add` by running `state.items.push(action.payload); state.total += action.payload.price; return state;`. After each click the Redux DevTools panel shows the new item in the store, but the rendered list never changes. What explains the stale screen?
MCQ-23A `todos` slice's `todos/added` reducer sets `createdAt: Date.now()`, and its action creator passes a `Todo` class instance as `payload`. In Redux DevTools the action log shows the payload as `{}`, and jumping back to an earlier action and replaying forward rebuilds every todo with the current time instead of the original. Which account of the broken time travel is right?
MCQ-17`CartBadge` renders the cart count with `const count = useCart(s => s.items.length)`. The `ProductCard` test clicks Add to cart and then asserts `expect(useCart.getState().items).toHaveLength(1)`. A refactor replaced the hook with a direct `useCart.getState().items.length` read in the component body; the suite stayed green while the badge rendered `0`. Which assertion should the test make instead?
MCQ-11A `CartPanel` calls `create(...)` in its component body to build a Zustand store and reads `const items = useCart(s => s.items)`. Clicking Add logs `useCart.getState().items.length` as `1` right after the action runs, the badge on screen still reads `0`, and a `console.log` inside the store creator fires on every render: in a production build too. Which account of the reset is right?
MCQ-5A dashboard component subscribes with `const { user, unread } = useSelector(s => ({ user: s.auth.user, unread: s.notifications.unread }))`. A websocket dispatches `presence/ping` ten times a second, touching only `s.presence`, and the Profiler shows the dashboard re-rendering on every one of those dispatches although `user` and `unread` never change. Which change stops those re-renders?
MCQ-10A Zustand store holds `items`, `cursor`, `lastSync` and `draft`; `cursor` is written on every `pointermove` (~60/s), `lastSync` by a 200 ms poll, and `draft` on each keystroke in a sibling editor. `CartBadge` renders `items.length` and subscribes with `const { items } = useStore()`, and the Profiler shows it re-rendering on every pointermove, poll tick and keystroke even though `items` changes only when the user adds a product. Which change makes `CartBadge` re-render only when `items` changes?
MCQ-1A React 18 app keeps its search term in a Zustand store. `SearchBox` calls `setQuery(e.target.value)` on every keystroke, and `AppShell` (the root layout rendering a 200-item sidebar, the results grid and the footer) subscribes with `const query = useSearchStore(s => s.query)` to render a 'Results for {query}' heading and pass `query` to the grid, which filters 5,000 rows. The Profiler shows a 40 ms commit of the whole shell per keystroke. Which change removes the per-keystroke commits?
MCQ-22`DocsShell` holds the search query in `useState` and returns `<div><SearchBox value={query} onChange={setQuery}/><ResultsPanel query={query}/><nav>{links.map(...)}</nav><article>{content}</article></div>`. `links` (300 entries) and `content` are module imports that never change, yet the Profiler shows a 45 ms commit of the whole shell on every keystroke. The query must stay in `DocsShell`. Which change stops `nav` and `article` re-rendering per keystroke?
MCQ-2In a React 18 app, `NotificationsProvider` holds `user` in state and a 1-second interval bumps `lastPing`; `markRead` is wrapped in `useCallback` with `[]` and `user` changes only on login. It passes `value={{ user, markRead }}` to its provider, whose 40 consumers come from a parent that does not re-render. The Profiler logs a render of all 40 consumers on every tick. Which account of those tick renders is right?
MCQ-9`LikeButton` gets `liked` and `likeCount` as props from a feed that re-renders on every websocket push with the post's authoritative values. Its `useState` copy is seeded once, set optimistically on click, and restored from the props captured at click time on failure. Another user's like never moves the count, a mid-request push flips the heart back, and a failed request can restore a stale count. Which rewrite fixes all three?
MCQ-6`ProductTable` keeps `const [filtered, setFiltered] = useState(items)` and an effect on `[items, query]` that runs `setFiltered(items.filter(p => p.name.includes(query)))`; `items` is a 500-product catalogue refreshed by a poll every 5 s and `query` comes from the URL. With the query `ssd` (12 matches) the grid paints all 500 rows for one frame before settling, and each keystroke commits twice. Which change is right?
MCQ-21A checkout form keeps eight fields in eight `useState` calls plus a `useEffect` watching all eight that writes `isValid` into a ninth state value, and clears `promoCode` and `postalCode` when `country` or `shippingMethod` changes. That two-field reset is written out in three handlers and the copies have drifted; the promo field clears one keystroke after typing and submit enables one render late. The form is one route-level component. Which change fixes the model?
MCQ-12In a React 18 app, `ThemeToggle` in the account menu needs `theme` and `setTheme`, and the pair is currently threaded `App → Shell → Sidebar → Nav → Menu → MenuList → MenuFooter → ThemeToggle` as props that the six middle components accept and forward but never read; all six come from a vendored design-system package the team cannot edit or re-publish. Which change removes the pass-through props with the least disruption?
MCQ-3A charting app tracks the pointer in a `MousePositionContext` whose provider calls `setState` on every `pointermove`: roughly 60 times a second. Forty consumers read `{x, y}` from that context to position their own overlay element, and the app drops frames while the pointer moves. Which change removes the per-frame re-renders?
MCQ-16A `SearchBox` dispatches `search/queryChanged(term)` on every keystroke and a `createAsyncThunk` fetches `/api/search?q=`. The box already debounces 250 ms, so typing `react` fires three requests, and the response for `rea` (p95 900 ms) lands after the one for `react` and overwrites `state.search.results`; `SearchResults` and `SearchCount` both read that single array. Which change makes the store hold only the newest term's results?
MCQ-8A metrics dashboard uses TanStack Query v5. The `QueryClient` is created with `defaultOptions: { queries: { staleTime: 5 * 60 * 1000, refetchOnWindowFocus: 'always' } }`, and the `useQuery` for `/api/metrics` passes no per-query overrides. Users report that every time they switch back to the tab, the network tab shows a new `GET /api/metrics`, even when the last fetch was seconds ago. The team wants to keep the 5-minute freshness window but stop the focus refetches. Which change achieves that?
MCQ-7A team's `orders` slice holds `items`, `isLoading` and `isError`, filled by thunks. `OrderList` fetches `GET /orders`, `OrderDetail` fetches `GET /orders/:id`. After a status PUT the list refetches but the open detail panel keeps the old status until remount, and three components mounting in one tick fire three identical GETs. They want the flags gone, the cache in the same Redux DevTools timeline as 12 other slices, and cleared by the existing `session/logout` reducer. Which change fits?
MCQ-13A comment thread holds 50,000 comments nested up to 40 levels deep in one `comments` array of arrays. Editing a comment's text runs a recursive `map` that rebuilds every array and every comment object it visits, and the Profiler shows a 180 ms commit with the whole thread re-rendering on each keystroke. Which state shape makes an edit touch one comment instead of the tree?
MCQ-14`ProjectPanel` renders a `DeleteProjectButton`, which renders a `<ConfirmDialog>` and keeps its open flag as `isDeleteDialogOpen` in the app's persisted Redux `ui` slice; no other component reads or dispatches it. Switching to another project and back remounts `ProjectPanel` with the dialog already open, and a browser reload reopens it too. Which change is right?
MCQ-15A dashboard's filter bar sets `region`, `status` and a date range. Today those filters live in a Zustand store persisted to `localStorage`. Two reports: a link pasted into Slack opens with the recipient's own last-used filters instead of the sender's, and pressing Back after a filter change leaves the dashboard instead of undoing that change. The page is a Next.js App Router page whose server component reads the filters to fetch initial data. The fix must make the sender's exact view reproducible from a link and make Back undo one filter change at a time. Which change meets both requirements?
MCQ-19A Next.js App Router page renders a `ThemeBadge` that calls `localStorage.getItem('theme')` in the component body and renders a sun or moon icon. The server HTML always shows the sun; on the client React logs a hydration mismatch for the badge and falls back to client rendering for the whole root. Which change fixes the mismatch?
MCQ-18A Next.js 14 App Router app exports `export const store = configureStore({ reducer })` from `lib/store.ts`. The root layout's server component reads `store.getState().session.user` to render the account menu, and a route handler dispatches `session/login` into the same import. After a deploy, users report the account menu showing a stranger's name and email until they hard-refresh, and the reports spike when traffic does. Which change fixes it?
MCQ-20A React 18 SPA keeps the cart in a Zustand store built with `create()` and no `persist` middleware, and the header badge renders `items.length`. Product wants a second tab on the same origin to show any add or remove from the first within a frame or two, and the team has ruled out writing anything to `localStorage` or `sessionStorage` because the cart is session-scoped and a reload must start empty. Which mechanism should the store use to publish each change?
MCQ-24A checkout widget is embedded on partner sites through a `<script>` tag. It is a React 18 app that ships 40 kB gzipped against a hard 50 kB cap, has no server rendering, and shares one value, the selected currency, between a `<CurrencyPicker>` and six price components. The value must survive a page reload, and the partner's own non-React analytics script must be able to get and change it. The team has never used Redux. Which choice fits the constraints?
MCQ-25A React 18 app runs Redux Toolkit for auth, cart and UI state in 12 slices, persisted to localStorage with `redux-persist`. The team is adding a media library: 40 REST endpoints and cursor-paginated infinite feeds. The query cache must survive a reload, rehydrate from IndexedDB with a 24-hour max age, and be dropped wholesale when a `buster` string changes; it runs to roughly 40 MB of JSON. Which setup fits?