01
Components and rendering
4 questionsQ01
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.
<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 questionsQ05
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.
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.
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.
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 questionsQ09
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.
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.
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.
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?
06
Practical UI behavior
3 questionsQ20
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.
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 DOINGBuild your preparation plan.
- 01
Start with rendering and identity, then state updates.
- 02
Practise effects, cleanup, and request races with an autocomplete.
- 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.