Skip to content
Tech Interview Prep
Technical interview guide

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.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v2
Editorial status
Reviewed

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..

Overview

Curated: · Written: · Reviewed:

React State Management

In one line

Decide who owns a value, how long it lives, and who may write it, then pick the lowest tool that answers that. Use local state or lifting for values one subtree needs, Context for read-mostly values such as theme or current user, an external store for client state that updates often or has many readers, and a query library for anything fetched over HTTP.

Key definitions

  • Ownership: the component allowed to change a value. Context changes the read path, not the owner.
  • Lowest common owner: the nearest ancestor that every reader sits under. It owns the state.
  • Server state: data owned by a backend. It is asynchronous, shared, and stale on arrival.
  • Selector: a function that picks the slice of a store a component subscribes to.
  • Referential stability: the value keeps the same identity under Object.is across renders.
  • Tearing: a concurrent render showing two components different versions of one store. useSyncExternalStore prevents it.

How it works

  • A provider publishes value and every consumer re-renders when that value fails Object.is. A parent re-render with a new inline object counts as a change.
  • An external store notifies subscribers, and each useStore(selector) re-renders only when its selected result changes.
  • A query cache keys data by query, deduplicates concurrent requests, revalidates in the background, and is invalidated after mutations.
no yes yes no Provider re-renders value identical by Object.is? Every Context consumer re-renders Consumers skip Store update selected result changed? That component re-renders Component skips

When to use and when not to

SituationToolWhy
One component reads and writes ituseState or useReducerThe lowest owner is the component
Two siblings need itLift to parentOwner is explicit, no new dependency
Deep tree, read-mostly, low churnContextBuilt in, cheap, fine for theme or locale
Same value, updates every frameExternal store or CSS variablesContext re-renders every consumer per update
Many writers, complex transitions, time travelRedux ToolkitConventions and devtools justify the ceremony
Small global client stateZustandSmall core, selector subscriptions
Anything fetched over HTTPTanStack Query, RTK Query, SWRCaching, deduplication, and revalidation are the job
Derived from props or stateCompute during renderNo state, no sync bug

Traps interviewers probe

  1. Inline Context value. value={{ user, setUser }} re-renders every consumer on each parent render. Fix: memoize the value, or split the setter into its own context so it never changes.
  2. Selector returning a new object. useSelector(s => ({ a: s.a, b: s.b })) re-renders on every dispatch. Fix: pass shallowEqual or useShallow, or select each field separately. React.memo on children does not stop a context update.
  3. Derived state in useState. Copying items into state with a useEffect renders a stale value first. Fix: compute filtered during render.
  4. Mutating state in place. Writing state.items.push(x) outside an Immer draft keeps the same reference, so selectors see no change and the screen stays stale. Fix: return a new reference, or use createSlice, which drafts with Immer.
  5. Context as a high-frequency store. Mouse position or scroll offset in Context re-renders every consumer per event. Fix: an external store read through selectors.

Interview tips

Open with ownership and lifetime: name the lowest common owner, how long the value lives, how often it changes, and how many components read it. Then name the tool.

Expected follow-ups:

  • A theme read by 200 components and a cursor read by 3: same tool? No. The re-render rule decides it, not the library.
  • Why React.memo does not stop context updates.
  • staleTime versus gcTime in TanStack Query: one controls freshness, the other how long unused data stays cached.
  • Why a module-level store can leak one user's state into another's response during SSR. Fix: a store factory with one instance per request.

30-second outline: one sentence on ownership and lifetime. One sentence on update frequency and reader count. The tool choice and why. One re-render trace, such as the inline value that re-renders all consumers and how memoizing or splitting fixes it. One trade-off, such as Zustand's smaller surface against Redux's enforced conventions.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.