Skip to content
Tech Interview Prep
Technical interview guide

React Fundamentals

The rendering model, state as a snapshot, keys and component identity, effects as synchronization, memoisation, and the client boundary.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: React 19, including automatic batching from React 18 and the Server Component model as implemented by React 19 and Next.js 16.

Overview

Curated: · Written: · Reviewed:

React Fundamentals

In one line

React calls your components to calculate the UI (render), then writes only the difference to the DOM (commit). Reach for this model whenever a bug depends on when code runs, which covers most React bugs an interviewer will raise. Rendering must stay pure, state is a snapshot per render, and effects exist only to synchronize with systems outside React.

Key definitions

  • Render: calling components to compute output. Same props, state and context must give the same JSX.
  • Commit: the step where React applies the computed changes to the DOM. Effects run after it.
  • State snapshot: a state value is constant for one render. A setter schedules the next render and does not change the value the running code holds.
  • Updater function: setN(prev => prev + 1). Queued and applied in order during the next render.
  • Identity: React keeps state while the same component type stays at the same position, or the same key among siblings.
  • Effect: code that keeps something external (subscription, socket, timer, widget) in sync with props and state. Cleanup runs before the next run and on unmount.
  • Derived value: computed during render from props and state, never copied into state.

How it works

  1. An event schedules updates. React batches every update from one event (and, since React 18, from promises and timeouts) into one render.
  2. Render calls components. The updater queue resolves in order, and each render gets its own snapshot.
  3. React compares the output with the previous one and commits only the changed DOM. If nothing changed, the commit is skipped.
  4. Effects run after commit. Cleanup from the previous run executes before the next setup.
  5. Identity decides preservation. Same type at the same position, or the same key, keeps state. Anything else unmounts it.
yes no Event calls setState Batched update queue Render: call components, apply updaters Output changed? Commit: write DOM Skip commit Effects: cleanup, then setup

When to use and when not to

SituationUseAvoid
Value computable from props or stateDerive during renderCopying it into state and syncing with an effect
Next value depends on previousUpdater functionRepeating a captured value
Work caused by a click or submitEvent handlerEffect watching a flag the handler sets
Subscription, socket, DOM widgetuseEffect with cleanupSide effects in the component body
Measure, then reposition before paintuseLayoutEffectuseEffect (one frame at the wrong position)
Value the screen readsStateRef (writes do not re-render)
Expensive calculation, stable inputsuseMemo after profilingmemo on everything
Reset child per recordkey={recordId}Effect that resets state on prop change
Frequently changing shared valueLocal state or a store with selectorsOne context holding everything

Traps interviewers probe

  • Calling setCount(count + 1) three times adds 1, because all three read the same snapshot. Fix: setCount(c => c + 1) for each call.
  • Defining a component inside another component's body creates a new type every render, so its state is lost on each render. Fix: move it to module scope.
  • Using the array index as a key on a list that can be reordered or inserted into. Focus and state stay with the position, so typed text lands in the wrong row. Fix: key on a stable id from the data.
  • Copying a prop into state. Later parent updates are ignored, and the input shows the first value. Fix: derive the value, or lift the state so the parent owns it.
  • Effects without cleanup. A slower earlier response can overwrite a newer one, and StrictMode in development runs setup twice. Fix: a local active flag or an AbortController, returned from cleanup.

Interview tips

Open with the split: "Render is a pure calculation, commit is the only write, and effects are for outside systems." Then name the mechanism the question turns on (snapshot, identity, or cleanup) before giving the fix.

Expect these follow-ups:

  • Why does StrictMode run component bodies twice, and what does that expose? Impure renders and missing cleanup.
  • When is an updater function needed? When the next value depends on the previous one.
  • Why does a key change reset state? Identity changes, so React unmounts and mounts a new subtree.
  • Why does a context change re-render everything? Consumers compare the provider value by identity, so an object literal changes on every render.
  • Where should use client go? On the smallest interactive leaf, so server-only imports stay out of the bundle.

30-second outline: "State is a snapshot for each render, so updates queue and a handler cannot read its own new value. Render must stay pure, and commit is where DOM changes happen. Keys set identity, and a changed key or type resets state. Effects synchronize with external systems and need cleanup, which StrictMode checks in development. I would derive values instead of storing them and profile before memoising."

Feedback on this overview

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