State management: React Context patterns, kinds of state and where it lives (Redux, Zustand, context) – Front End interview prep
777 interview-style multiple-choice questions on State management (Redux, Zustand, context), organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 54 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 7.1 Kinds of state and where it lives
- 7.2 React Context patterns
- 7.3 Redux fundamentals
- 7.4 Redux Toolkit and RTK Query
- 7.5 Zustand, Jotai and lightweight stores
- 7.6 Signals and fine-grained reactivity
- 7.7 Server state with TanStack Query and SWR
- 7.8 URL, form and persisted state
- 7.9 Choosing and scaling a state architecture
Key terms
7.1 Kinds of state and where it lives
- Client state
- Data owned by the UI, such as form inputs, toggles and preferences
- Derived state
- Values computed from other state instead of being stored
- Ephemeral state
- Short-lived client state that does not need to survive a reload, such as hover or open flags
- Global state
- State readable from many distant parts of the client; useful when shared, costly when overused
- Impossible state
- A state combination that should never occur
- Local state
- State owned by one component or a narrow parent, rather than by a global store or the server
- Normalized state
- Entities stored once by ID and referenced elsewhere
- Server state
- Data owned by the backend that must be fetched, cached and kept fresh
- State machine
- Model with explicit states and allowed transitions
- State shape
- How state is arranged so updates stay simple and facts are not stored in several places
- Store
- An object that holds state and notifies subscribers when it changes
- UI state
- Short-lived client state like open menus or focus
- Unidirectional data flow
- Views read state downward and request changes by sending events or actions upward
7.2 React Context patterns
- Context
- React's mechanism for passing a value through the tree without props
- Context selector
- Reading only part of shared state to limit re-renders
- Prop drilling
- Passing props through many layers that don't use them
- Provider
- The component that supplies a context value to its subtree
- Provider hell
- Deeply nested providers at the app root
- useContext
- Hook that reads the nearest matching context provider above a component
- Default context value
- The value createContext supplies when no matching provider is above the consumer
- Value identity
- Whether a provider's value is Object.is-equal to the previous one; a new object re-renders every consumer
- use()
- React 19 API that can read a context or Promise and may be called conditionally during render
- Context splitting
- Providing separately updating values through different context objects so they have different subscribers
- displayName
- A label you set on a context object so DevTools can name the provider and its consumers
7.3 Redux fundamentals
- Action
- A plain object describing what happened, with a type field
- Immer
- Library that lets you write mutating code on a draft and produces immutable updates
- Memoized selector
- Selector that recomputes only when inputs change
- Middleware
- Code between dispatch and the reducer
- Reducer
- A pure function (state, action) => newState
- Selector
- A function that reads (and can derive) a value from the store
- Thunk
- Function dispatched to run async logic
7.4 Redux Toolkit and RTK Query
- createAsyncThunk
- RTK helper that dispatches pending, fulfilled and rejected
- Entity adapter
- RTK helper for normalized collections
- Redux Toolkit
- Official, batteries-included way to write Redux
- RTK Query
- RTK's data fetching and caching layer
7.5 Zustand, Jotai and lightweight stores
- Jotai
- Atomic state library built from small atoms
- Signal
- A reactive value that updates only its dependents when it changes
- TanStack Query
- Library for fetching, caching and synchronizing server state
- Valtio
- Proxy-based state you can mutate directly
- XState
- State machine and actor library
- Zustand
- A small hook-based store with selector subscriptions and no provider
7.6 Signals and fine-grained reactivity
- Computed
- Derived reactive value that's cached
- Fine-grained reactivity
- Updating only the DOM parts that depend on a change
- Glitch
- Observers seeing inconsistent intermediate values
7.7 Server state with TanStack Query and SWR
- gcTime
- How long inactive data stays cached
- Invalidation
- Marking cached data stale so it refetches
- Query key
- Array identifying cached data in TanStack Query
- staleTime
- How long data is considered fresh
7.8 URL, form and persisted state
- Dirty field
- Form field changed from its initial value
- Partial persistence
- Saving only chosen fields of a store
- URL state
- State kept in the path or query string
7.9 Choosing and scaling a state architecture
- God store
- One huge store every feature depends on
- Offline-first
- Writing locally first and syncing later
- Outbox
- Local queue of writes sent when back online
Sample practice questions
Which kind of state is the best fit for a global store such as Redux or Zustand?
- Data fetched from the server that needs caching and refetching
- Client state many distant components share, like a cart
- The text of a single input that only its own component reads
- A value that can be computed from other state during render
Answer: B. Client state many distant components share, like a cart Keep local UI state local, server data in a server-state cache, and derived values computed rather than stored.
What happens when a context provider's `value` changes?
- Nothing changes on screen until the page is reloaded
- Only components reading the specific changed field re-render
- Every component reading that context re-renders
- Only the provider re-renders, not its consumers
Answer: C. Every component reading that context re-renders Context has no selector; large contexts can cause many unnecessary renders.
In Redux, what is a reducer?
- A function that sends actions to the server and waits for a reply
- A middleware that logs every action to the console
- A pure `(state, action) => newState` function that doesn't mutate
- A component that subscribes to the store and re-renders
Answer: C. A pure `(state, action) => newState` function that doesn't mutate Pure reducers make state changes predictable, testable and replayable in devtools.
Why can Redux Toolkit's `createSlice` reducers write `state.items.push(x)`?
- RTK uses Immer, which turns draft "mutations" into new state
- The store is a mutable singleton anyway
- `push` is overridden to copy the array first
- Redux has allowed direct mutation since version 5
Answer: A. RTK uses Immer, which turns draft "mutations" into new state You still get immutable updates; just don't both mutate the draft and return a new value.
How does a Zustand store differ from a Context-based store?
- No provider; components re-render only when their selected slice changes
- Zustand stores need a provider at the root, just like Context does
- Zustand can only hold primitive values like strings and numbers
- Every component re-renders whenever any part of the store changes
Answer: A. No provider; components re-render only when their selected slice changes `const count = useStore(s => s.count)` re-renders only when `count` changes.
What is a "signal" in libraries like Preact Signals, Solid or Angular?
- A WebSocket message pushed from the server
- A reactive value that updates only the code that reads it
- A browser event fired on every state change
- A Redux action that carries a timestamp
Answer: B. A reactive value that updates only the code that reads it Fine-grained reactivity can update the exact DOM node instead of re-rendering a component.
Why is server-state caching (TanStack Query, SWR, RTK Query) often a bigger win than a global store?
- They remove the need for a backend API altogether
- Most "global state" is fetched data, which they cache and refresh
- They write data to the database directly from the browser
- They make API calls synchronous, so no loading states are needed
Answer: B. Most "global state" is fetched data, which they cache and refresh After moving API data to a query cache, the remaining client state is often small.
What belongs in the URL rather than in a store?
- The whole Redux store, serialized as JSON for safekeeping
- Access tokens and other secrets, so they survive reloads
- State users share, bookmark or restore with Back, like filters
- Every keystroke in a form, so drafts are never lost
Answer: C. State users share, bookmark or restore with Back, like filters URL state survives reloads and links; never put secrets in it.
What is the main argument against putting everything in Redux?
- Boilerplate for state that's local, derived or server cache
- Redux forces the app to use server-side rendering
- Redux doesn't work with TypeScript projects
- Redux can't hold more than 1 MB of state
Answer: A. Boilerplate for state that's local, derived or server cache Use Redux for shared, complex client state where its structure and tooling pay off.
What is "server state" and why is it different from client state?
- Backend-owned data that can change, so it needs caching and refetching
- Any state stored in a cookie, sent with every request automatically
- State that only exists while the page is rendered on the server
- State kept in a Redux store that runs inside the server process
Answer: A. Backend-owned data that can change, so it needs caching and refetching Libraries like TanStack Query or SWR handle loading, caching, deduping and background refresh for it.
More Front End
- HTML semantics & accessibility
- CSS: box model, Flexbox, Grid
- JavaScript fundamentals
- Async JavaScript & the event loop
- TypeScript
- React: components, hooks & rendering
- Angular and Vue basics
- Browser internals & rendering
- Web performance
- Build tools & bundlers
- Front-end testing
- Front-end security
- Mobile & cross-platform