Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  The React Interview Handbook
Handbook~16 min readIntermediate
Interview Prep

React interviews,
and the render under it all.

React interviews rarely ask you to memorize an API. They probe whether you understand the model: UI as a function of state, why components re-render, and how hooks and reconciliation actually behave. Get that mental model and the questions answer themselves.

01

Components, JSX & the declarative model

A React app is a tree of components — functions that take inputs and return a description of UI written in JSX (which compiles to React.createElement calls). The defining idea is that React is declarative: you describe what the UI should look like for a given state, not the step-by-step DOM mutations to get there. The mental model is a single equation:

UI = f(state)

You never manually add or remove DOM nodes; you change state, and React figures out the DOM changes. This is the whole philosophy — and why the interview questions cluster around state, rendering, and how React turns your declarations into efficient updates.

02

Props vs state

Two kinds of data drive a component. Props are inputs passed in by a parent — read-only from the component's view; a component never mutates its own props. State is data a component owns and can change over time; updating it triggers a re-render.

Data flows one way: state lives in some component and flows down to children as props ("props down, events up" — children request changes by calling callbacks passed as props). A frequent interview point is lifting state up: when two components need the same data, you move that state to their nearest common parent and pass it down, keeping a single source of truth. Unidirectional flow is what makes React apps predictable.

→ The distinction

Props are read-only inputs from above; state is mutable data a component owns. If a value never changes within the component, it's a prop. If the component changes it over time and re-renders, it's state.

03

The render cycle & reconciliation

When state changes, React renders: it calls your component functions to produce a new tree of elements — the virtual DOM, a lightweight in-memory description of the UI. It then reconciles: diffs the new tree against the previous one and computes the minimal set of real DOM operations to make the browser match. The real DOM is slow to touch; the virtual DOM diff lets React batch and minimize those touches.

Rendering (calling your function) is not the same as committing to the DOM — React renders in memory, then commits only the differences. Understanding this split explains a lot: a re-render isn't automatically expensive DOM work, but it does run your component code and its diff, which is why avoiding unnecessary renders still matters at scale.

State change → render → reconcile → commit
1 · TriggerState/props change — schedules a re-render of the component (and descendants).
2 · RenderCall the component — produce a new virtual DOM tree (in memory, no DOM touched).
3 · ReconcileDiff new vs old tree — find the minimal changes.
4 · CommitApply just those changes to the real DOM.
04

Hooks & their rules

Hooks let function components use state and lifecycle features. The essentials: useState holds local state and returns a value + setter; useEffect runs side effects (data fetching, subscriptions) after render, controlled by a dependency array — it re-runs when a listed dependency changes, and its returned cleanup function runs before the next effect and on unmount (unsubscribe, clear timers). useMemo memoizes an expensive computed value; useCallback memoizes a function's identity.

The rules of hooks are a favorite interview question: only call hooks at the top level (never inside conditions, loops, or nested functions) and only from React function components or custom hooks. Why? React tracks hooks purely by their call order on each render — so the order must be identical every time, or state gets associated with the wrong hook. Break the rule and state silently corrupts.

→ The useEffect trap

The dependency array is the #1 hooks bug source. Omit a dependency and the effect uses stale values; include an unstable one (a new object/function each render) and it re-runs endlessly. Get the deps exactly right — and use the cleanup function for anything that subscribes or schedules.

05

Why re-renders happen — and memoization

A senior interview will push on performance. A component re-renders when: its state changes, its parent re-renders, or a context it consumes changes. The common problem is a parent re-render cascading to children that didn't need to update — often triggered by passing a new object or function reference as a prop each render (inline {} or () => creates a fresh reference, which looks like a changed prop).

The tools: React.memo skips a component's re-render if its props are unchanged (shallow-compared); useMemo keeps an object/computed value stable across renders; useCallback keeps a function identity stable so a memoized child doesn't see a "new" prop. But the crucial senior insight: memoization isn't free and isn't always a win — it costs memory and comparison, and applied everywhere it can make things slower and code noisier. Measure first, then memoize the hot paths that actually re-render too much.

ToolMemoizesUse to
React.memoA whole componentSkip re-render when props are unchanged
useMemoA computed value/objectAvoid recomputing, or keep a reference stable
useCallbackA function's identityStop a memoized child seeing a "new" function prop
06

Keys & list rendering

When you render a list, React needs a key on each item — a stable, unique identifier that tells reconciliation which item is which across renders. With keys, React can tell that an item moved, was added, or removed, and update efficiently while preserving each item's state.

The classic interview trap: using the array index as a key. It works until the list reorders, inserts, or deletes — then indexes shift, React mismatches items, and you get subtle bugs (an input's value attaching to the wrong row, wrong items animating). Use a stable id from your data, not the index. Keys are how React keeps identity straight in a dynamic list.

07

Controlled vs uncontrolled inputs

For form inputs, React distinguishes two patterns. A controlled component has its value driven by React state (value={x} + onChange) — React is the single source of truth, so you can validate, transform, and react to every keystroke. An uncontrolled component lets the DOM hold the value, and you read it via a ref when needed — simpler, less code, but you give up per-keystroke control.

Controlled is the React-idiomatic default and what interviewers usually expect, because it keeps the input consistent with your state model. Uncontrolled is fine for simple forms or integrating non-React widgets. The tell: if you need to know or shape the value as the user types, control it; if you just need the final value on submit, uncontrolled with a ref is lighter.

08

Context & state management

Prop drilling — threading a value through many intermediate components that don't use it — is a smell. Context solves it: provide a value at a high level and consume it anywhere below without passing props through every layer, ideal for app-wide data like theme, current user, or locale.

But context isn't a general state manager, and the senior nuance is a common question: every consumer re-renders when the context value changes, so putting frequently-changing state in one big context can cause broad re-renders. Split contexts by concern, memoize the provided value, and for complex or high-frequency state reach for a dedicated state library (Redux, Zustand, and friends) or server-state tools (React Query) rather than overloading context. Choose the lightest tool that fits: local state → lifting → context → a store, in that order of escalation.

→ The escalation ladder

Start with local useState. Shared between siblings? Lift it up. Needed app-wide and rarely changing? Context. Complex, high-frequency, or server data? A dedicated store or query library. Don't jump to Redux for a toggle.

By the numbers

Worked example: two classic questions, step by step

Two snippets come up in React interviews again and again, because both test the same model: each render sees its own snapshot of state. Part A is a button whose handler calls setCount(count + 1) three times. Part B is an interval set up in useEffect(…, []). Both start at count = 0.

StepCode runscount in this closureUpdate queuedResult
A1setCount(count + 1)0“set to 1”Not applied yet; the handler keeps running
A2setCount(count + 1)0“set to 1”Same snapshot, same value
A3setCount(count + 1)0“set to 1”Three updates, batched into one render
A4Re-render1—count = 1, not 3
A5setCount(c => c + 1) ×3ignored0→1, 1→2, 2→3count = 3: each updater gets the previous result
B1Effect runs once (deps [])0Interval calls setCount(count + 1)The callback closes over count = 0
B2Tick 10“set to 1”count = 1, re-render
B3Tick 2, 3, …0, forever“set to 1”Stuck at 1: the effect never re-ran, so the closure is stale
B4Fix: setCount(c => c + 1)not readincrementCounts 1, 2, 3… with deps still []

Same cause, both times. A render’s count is a constant for that render. Setting state asks for a future render. It does not change the variable you are holding. The updater form c => c + 1 sidesteps the snapshot, which is why it fixes both. In Part B, adding count to the deps also works, but then the interval is torn down and recreated on every tick.

Trade-offs

Cost and trade-offs: what each tool costs you

For these tools, read Time as what runs on each render, and Space as what is kept between renders.

CaseTimeSpaceWhy
Plain re-renderRuns the component function and diffs its subtreeNothing extraUsually cheap. It gets expensive with large subtrees or heavy work inside the render body.
React.memoShallow-compares every prop on each parent renderThe previous propsWins when props are stable and the child is costly. Loses when a prop changes every time, because you pay for the compare and the render.
useMemo / useCallbackCompares the dependency array each renderThe cached value or functionuseCallback only helps if the receiver is memoized or lists the function in its own deps.
Context value changeEvery consumer below re-rendersOne value per providerReact.memo does not stop it. Split contexts, and memoize the value object.
Controlled inputA state update and a render per keystrokeThe value in stateFull control (validate, format as you type). In a large form, keep the state local to the field.
Uncontrolled input + refNo renders while typingThe value lives in the DOMLight, but you read it only when you ask, such as on submit.
Lifting state upThe common parent and its subtree re-render on each changeOne source of truthCorrect sharing, wider renders. Lift only as high as the nearest common parent.
Changing a keyUnmount + mount of that subtreeFresh stateIntentional resets, such as a new user’s form, at the price of a full mount.

Interviewers want the second half of each answer: what you pay for the optimisation, and how you would know it was worth it (the Profiler, before and after).

Watch for

Common mistakes

  • Mutating state, then setting it

    items.push(x); setItems(items) passes the same array reference. React compares with Object.is, sees no change and may skip the render entirely. Always make a new value: setItems([...items, x]).

  • Reading state right after setting it

    setCount(5); console.log(count) logs the old value. The setter schedules a render and does not change the local constant. Use the value you just computed, or react to the new state in the next render.

  • Mirroring props into state with an effect

    A useState copy of a prop, kept in sync by useEffect, renders once with the stale value and then again with the fresh one. If a value can be computed from props or state, compute it during render (with useMemo if it is expensive). The React docs cover this under “You Might Not Need an Effect”.

  • “Render” used to mean “DOM update”

    A render calls your function and builds a tree in memory. The commit is when the DOM changes, and only for the differences. Mixing the two up leads to wrong answers about cost: a component can render a hundred times and commit nothing.

  • Memoizing everything

    Wrapping every function in useCallback while the children are not memoized adds comparisons and noise, and saves no renders. Memoize where the Profiler shows a costly re-render, and make sure the receiving side can actually use a stable reference.

In the wild

Where this shows up in interviews and in production

  • “Why does my effect run twice?”

    In development, Strict Mode mounts each component, unmounts it and mounts it again, so an effect’s setup and cleanup both run an extra time. It is there to expose effects with a missing cleanup. It does not happen in production builds, and the fix is a correct cleanup, not removing Strict Mode.

  • Search box with fetch

    A favourite live-coding task. Typing “re” then “react” starts two requests, and if the first returns last, it overwrites the right results. In the effect’s cleanup, abort the request (AbortController) or set an ignore flag, and debounce the input.

  • Performance debugging

    The React DevTools Profiler records which components rendered, how long each took and, with the setting turned on, why each one rendered. The interview answer to “this page is slow” starts with measuring, not with React.memo.

  • State placement in a design round

    Frontend system-design rounds ask where each piece of state lives: local, lifted, context, a store, or a server-state cache. Name the escalation ladder from the page, and say what each step costs in re-renders.

Self-check

Check yourself

A parent renders <Row onSelect={() => pick(id)} /> and Row is wrapped in React.memo. The parent re-renders for an unrelated reason. Does Row re-render?

Yes. The inline arrow is a new function on every render, so the shallow compare sees a changed prop and React.memo does nothing. Wrap the handler in useCallback with [id] as deps, or pass id and a stable pick down separately.

App provides value={{ user, setUser }} to a context. App re-renders because a clock ticks. What happens to the context consumers?

They all re-render. The object literal is a new reference every render, so React sees a new context value, even though user did not change. Memoize it: useMemo(() => ({ user, setUser }), [user]), or move the clock state out of App.

An input has value={name} and no onChange. What does the user experience?

Typing does nothing, and React warns in development. A controlled input always shows the state value, and with no handler that state never changes. Add onChange, use defaultValue for an uncontrolled input, or mark it readOnly if that is intended.

You render <EditForm key={doc.id} doc={doc} />. The user opens a different document. What happens to the half-typed draft?

It is discarded. A new key means React unmounts the old EditForm and mounts a fresh one with fresh state. That is usually the point: each document gets its own clean form without an effect that resets every field. If drafts should survive, keep them in state above the form, keyed by document id.

Frequently asked

Quick answers

Props vs state?

Props are read-only inputs passed in by a parent; state is data a component owns and can change, triggering a re-render. Data flows one way: state down as props, changes up via callbacks.

Virtual DOM & reconciliation?

The virtual DOM is an in-memory UI description. On a state change React builds a new tree, diffs it against the old (reconciliation), and applies the minimal real-DOM updates — letting you write declarative code.

Why does a component re-render?

Its state changed, its parent re-rendered, or a context it uses changed. Unnecessary cascades from unstable props are fixed with React.memo, useMemo, and useCallback — but measure before memoizing.

The rules of hooks?

Call hooks only at the top level (not in conditions/loops) and only from components or custom hooks, because React tracks them by call order — the order must be identical every render.

Finished this one? 0 / 209 Handbooks done
Next50 Angular Interview Questions Next on the “The languages you ship in” ladder · rung 5 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.