HelloFrontendInterview handbookFREE REVISION COLLECTION
THE REACT COLLECTION

React
interview questions.

For frontend candidates who already know basic JSX and want to explain React behavior clearly. Read an answer, predict the example, then attempt the linked exercise before opening its solution.

22 questions06 topicsAnswers + practical examples
Start revising
01

Components and rendering

4 questions
Q01

How do props and state differ?

Props are inputs supplied by a parent; state is memory owned by a component. Both are snapshots for a particular render. A child requests changes through callbacks rather than mutating its inputs. Lift shared state to the closest common owner.

Common mistake

Copying a prop into state without a synchronization policy creates two competing sources of truth.

Go one level deeper

Where would you put the selected tab shared by a tab bar and panel?

Q02

What causes a component to render?

Initial mounting, its own state updates, parent rendering, and changes to context it reads can trigger rendering. Rendering computes the next UI; committing applies necessary DOM changes. A render need not change the DOM, and setting state to an Object.is-equal value can be skipped.

Common mistake

Assuming every render replaces DOM nodes leads to unnecessary optimization.

Go one level deeper

How would you measure whether the expensive work is rendering or layout?

Q03

How does React preserve component identity?

State belongs to a component type at a position in the rendered tree, with keys distinguishing siblings. The same type and key at the same position preserve state; changing them resets it. Defining component functions inside another component creates a new type on each render.

EXAMPLEREACT / JSX
<Editor key={record.id} record={record} />

Common mistake

Nested component definitions can unexpectedly reset input and child state.

Go one level deeper

How can you reset a form when switching between records?

Q04

What is reconciliation?

React compares the next element tree with the previous one and uses types and keys to decide what can be reused. The render phase computes changes; the commit phase updates the host UI. This is a programming model for expressing UI, not a promise that React always beats direct DOM code.

Common mistake

Treating the virtual DOM as a universal performance guarantee ignores work in components and the browser.

Go one level deeper

Why can changing an element type discard the subtree?

02

State updates

4 questions
Q05

When should you use a functional state update?

Use an updater when the next value depends on the previous queued value. Each updater receives the result of preceding updates. Reading count twice in one event still reads the same render snapshot. Updaters must be pure.

EXAMPLEREACT / JSX
setCount(c => c + 1);
setCount(c => c + 1); // adds two

Common mistake

Calling setCount(count + 1) twice usually queues the same replacement twice.

Go one level deeper

Why must an updater avoid an API request?

Q06

Why should state be treated as immutable?

Create new objects along the path you change, preserving untouched references. React and memoized consumers use reference comparisons; mutation changes past snapshots and may prevent updates from being recognized. A shallow spread does not clone nested objects.

EXAMPLEREACT / JSX
setItems(items => items.map(item =>
  item.id === id ? { ...item, done: true } : item
));

Common mistake

Copying the array and mutating one of its existing objects still mutates shared state.

Go one level deeper

How do you update one item without replacing every item object?

Q07

What does batching do?

React groups eligible updates to avoid intermediate renders. Modern roots batch updates from many callbacks, including promise and timer callbacks. The current function still sees its render snapshot. Separate intentional user events are handled separately; batching does not mean state becomes synchronously readable.

Common mistake

Reading state immediately after its setter and expecting the next value produces incorrect logic.

Go one level deeper

How do batching and queued functional updates work together?

Q08

Should derived values be stored in state?

Calculate values from current props and state during rendering when possible: filtered items, totals, and validity usually need no second state variable. Memoize an expensive calculation only after measuring. Store an independent user choice, not a duplicate of a calculation.

EXAMPLEREACT / JSX
const total = items.reduce((sum, item) =>
  sum + item.price * item.quantity, 0);

Common mistake

An effect that updates a derived total introduces an extra render and synchronization bugs.

Go one level deeper

When is a draft copied from server data intentionally independent?

03

Hooks and effects

5 questions
Q09

What belongs in an effect dependency array?

Include every reactive value used by the effect: props, state, and component-local variables or functions. React compares dependencies using Object.is. No array runs after every commit; an empty array means no reactive dependencies. Mounting again still runs setup, and development Strict Mode can add a setup/cleanup check.

EXAMPLEREACT / JSX
useEffect(() => {
  const connection = connect(roomId);
  return () => connection.disconnect();
}, [roomId]);

Common mistake

Removing a dependency to silence the linter leaves the effect synchronized with old values.

Go one level deeper

How could you restructure an effect to avoid a fresh object dependency?

Q10

When does effect cleanup run?

Cleanup runs before setup with changed dependencies and on unmount. It closes the resources created by that setup: timers, subscriptions, sockets, or pending work. Development Strict Mode exercises cleanup with an extra cycle, so setup and cleanup must tolerate repetition.

EXAMPLEREACT / JSX
useEffect(() => {
  const id = setInterval(tick, 1000);
  return () => clearInterval(id);
}, [tick]);

Common mistake

Cleaning up only on unmount leaves the old room subscription active when roomId changes.

Go one level deeper

What should happen if the component mounts, unmounts, and mounts again?

Q11

What is a stale closure in a hook?

A callback captures variables from the render that created it. A timer or subscription can keep reading an old value if its effect never resubscribes. Choose a functional updater for previous-state changes, correct dependencies for synchronization, or a ref for intentionally mutable data that does not render UI.

EXAMPLEREACT / JSX
useEffect(() => {
  const id = setInterval(() => setCount(c => c + 1), 1000);
  return () => clearInterval(id);
}, []);

Common mistake

Using an empty dependency array while reading changing state freezes the callback snapshot.

Go one level deeper

When would a ref hide a bug rather than fix it?

Q12

Why do Hooks have ordering rules?

State and effect Hooks must be called at the top level of a function component or custom Hook so their order stays stable across renders. Put conditions inside the effect, or extract a child component. Custom Hooks share logic; each invocation has its own state.

Common mistake

Calling useState after a conditional early return changes the Hook sequence.

Go one level deeper

How would you fetch only when a modal is open without calling Hooks conditionally?

Q13

When is an effect unnecessary?

Effects synchronize with external systems. Calculate display data during render and handle a user action in its event handler. Sending a purchase request because a boolean changed can accidentally repeat work on remount; tie it to the explicit action and design the server operation safely.

Common mistake

Chaining effects to calculate local state makes the update flow hard to reason about.

Go one level deeper

Where should filtering a list or sending a form submission live?

04

Lists and forms

3 questions
Q14

Why are array indices sometimes bad keys?

Keys identify siblings across renders. With index keys, inserting, sorting, or deleting can attach an existing row state to a different item. Use stable IDs from the data. Indices can be acceptable for genuinely static lists with no item identity changes; keys are not passed as regular props.

EXAMPLEREACT / JSX
// Sorting items preserves the correct Row state.
items.map(item => <Row key={item.id} item={item} />)

Common mistake

A checked checkbox or draft input can move to the wrong record after sorting.

Go one level deeper

Why is Math.random() as a key worse?

Q15

What makes an input controlled?

A controlled input receives its value from React state and updates that state through onChange. An uncontrolled input keeps its current value in the DOM and can use defaultValue or a ref. Keep a controlled text value a string throughout its lifetime and associate labels with inputs.

EXAMPLEREACT / JSX
const [name, setName] = useState('');
<input value={name} onChange={e => setName(e.target.value)} />

Common mistake

Switching from undefined to a string switches input ownership and can produce warnings.

Go one level deeper

When would an uncontrolled form reduce unnecessary work?

Q16

How do you reset component state deliberately?

Change the key when a different entity should start fresh, or explicitly reset the particular fields you own. A key reset recreates the entire subtree, including focus and effects, so it is broader than setting one field. Avoid an effect that briefly renders the previous record’s draft.

Common mistake

Resetting on every render discards typing; using the same identity for different records can retain stale drafts.

Go one level deeper

Would you reset the entire editor or only its validation messages?

05

Performance

3 questions
Q17

When do memo, useMemo, and useCallback help?

memo can skip parent-driven component rendering when props compare equal; useMemo caches a calculation and useCallback caches a function identity. They help when work is expensive or identity matters to an optimized consumer. Measure first: new object props can defeat memo, and caches are optimizations rather than semantic guarantees.

Common mistake

Wrapping every tiny expression adds complexity while leaving the expensive operation untouched.

Go one level deeper

Why does memo not prevent updates from a context the component reads?

Q18

Why can context cause many rerenders?

Consumers update when their provider value changes by Object.is, even if they use only one field of a larger value. Split providers by responsibility, keep state near its users, and stabilize provider objects when useful. For high-frequency granular subscriptions, consider an appropriate external store.

Common mistake

A new provider object on every parent render notifies consumers unnecessarily.

Go one level deeper

How would you isolate a rapidly changing search query from a theme context?

Q19

When should you virtualize a list?

Virtualization renders only visible rows plus an overscan buffer, reducing DOM and rendering work for large datasets. It needs height measurement, stable keys, and careful keyboard, focus, and accessibility behavior. Pagination limits data transfer; virtualization limits rendered nodes, so they can be combined.

Common mistake

Unmounting the focused row or assuming every row has equal height breaks interaction.

Go one level deeper

How would you preserve scroll position after prepending chat messages?

06

Practical UI behavior

3 questions
Q20

How should loading and error states be modeled?

Represent idle, loading, success, empty, and error states explicitly. Preserve previous data during refresh when useful, distinguish an initial failure from a background failure, and offer a retry. Error boundaries handle rendering errors in descendants, not ordinary rejected requests in event handlers.

Common mistake

One boolean cannot distinguish empty results from a failed request.

Go one level deeper

Should a retry clear the existing results or keep them visible?

Q21

How do you cancel work when a query changes?

Create an AbortController for a fetch and abort it during effect cleanup. Handle cancellation separately from real failures. Some work cannot be physically canceled; then ignore results from an obsolete request. Check response.ok because HTTP error responses do not normally reject fetch.

Common mistake

Displaying an AbortError as a user-facing failure makes rapid typing look broken.

Go one level deeper

Does canceling the client guarantee the server stopped processing?

Q22

How do you prevent a stale search response winning a race?

Tie each result to the active query or request ID. An old slow request can finish after a newer one; debouncing only reduces request frequency. Abort obsolete fetches and guard state updates with an active flag or sequence number. Apply the same protection to loading and error updates.

EXAMPLEREACT / JSX
useEffect(() => {
  let active = true;
  const controller = new AbortController();
  search(query, controller.signal).then(results => {
    if (active) setResults(results);
  }).catch(error => {
    if (active && error.name !== 'AbortError') setError(error);
  });
  return () => { active = false; controller.abort(); };
}, [query]);

Common mistake

Accepting every response can replace results for the current query with results for an earlier query.

Go one level deeper

How would you test two responses completing in reverse order?

FROM READING TO DOING

Build your preparation plan.

  1. 01

    Start with rendering and identity, then state updates.

  2. 02

    Practise effects, cleanup, and request races with an autocomplete.

  3. 03

    Build a form and a large list; profile before adding memoization.

Junior candidates: prioritize state ownership, inputs, keys, effects, and a complete basic UI.

Experienced candidates: explain performance evidence, async correctness, accessibility, and the trade-offs behind your choices.

Keep the references close.

These are editorial practice questions, not a verified list of questions asked by a particular company.