React Interview Questions on State: useState, Updates and Re-renders
Reviewed by Mark Dickie · Last updated
4 questions on this page you can answer and see marked on the spot. Go to the first one
React state is the data a component keeps between renders, and changing it is what makes React redraw the UI. Interviewers mostly test whether you know that a setter schedules a re-render rather than changing the value in place. They also check whether you can predict what a handler reads after an update, and when to lift state up or move it into useReducer. Expect small components where you trace the output by hand.
Which React state concepts do interviewers test?
| Concept | What to know | Typical trap |
|---|---|---|
| useState | Returns [value, setter]. The setter queues an update and triggers a re-render. | Reading the variable right after calling the setter still shows the old value. |
| Functional updates | setCount(c => c + 1) computes from the latest queued value. | setCount(count + 1) called twice in one handler increments only once. |
| Batching | React 18 and later batch state updates from event handlers, timeouts and promises. | Expecting one render per setter call. |
| Immutable updates | Setters compare with Object.is, so a new object or array must be created. | push() into the existing array changes it but skips the re-render. |
| Lifting state | Shared state moves to the nearest common parent and flows down as props. | Keeping copies of the same value in two siblings until they drift apart. |
| useReducer | Groups related transitions into a pure reducer(state, action) function. | Mutating the state object inside the reducer. |
| Context | Consumers re-render when the provider value changes identity. | Passing a new object literal as the value on every render. |
How should you practise React state questions?
- Predict the output of two setCount(count + 1) calls in one click handler, then rewrite it with the functional form.
- Build a form with one useState per field, then merge the fields into one object and update it without mutation.
- Lift a counter from a child into its parent, and explain which components re-render and why.
- Replace a useState setup with several related flags by a useReducer, and write the reducer as a pure function you can test.
Key facts
- Tarmac has 25 React interview questions on this topic, 10 of them on this page, at difficulty 1–4 of 5.
- Tarmac tracked 1,185 job postings asking for React in November 2026.
- Roles asking for React advertise a median base salary of £75,000, across 477 job postings as of November 2026.
- Tarmac last reviewed these React interview questions on 2 November 2026.
At a glance
| Questions | 10 shown · 25 in the bank |
|---|---|
| Difficulty | 1–4 of 5 |
| Formats | True / false, Fill in the blank, Code output, Flashcard, Multiple choice, Find the bug, Short answer, Multiple answer |
What you'll review
- external stores
- lifting state
- context api
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In React's useSyncExternalStore, getSnapshot must return a value that is identical under Object.is on consecutive calls while the store has not changed. Returning a new object or array with the same contents on each call violates this requirement.#
Options
Show answer
True. React's useSyncExternalStore requires getSnapshot to return a value that Object.is treats as identical while the store is unchanged. A new object or array with identical contents on every call fails that check, which makes React report that the result should be cached and can cause an infinite render loop.
React compares each snapshot returned by getSnapshot with Object.is, which is true only for the same primitive value or the same object reference. If the store has not changed, getSnapshot must therefore return the identical value every time. In development, React also calls getSnapshot twice in a row to verify this. A function like () => ({ count: store.count }) returns a new object on each call, so React logs 'The result of getSnapshot should be cached to avoid an infinite loop' and can re-render endlessly. The fix is to return a primitive or a cached, memoized object.
In React 18+, the built-in hook for subscribing a component to an external store takes a subscribe function and a getSnapshot function. Assume the hook is imported from 'react' and myStore is defined as shown below. Fill in the hook name as _____ and the store property that registers listeners as _____.#
Show answer
In React 18+, the built-in hook for subscribing a component to an external store takes a subscribe function and a getSnapshot function. Assume the hook is imported from 'react' and myStore is defined as shown below. Fill in the hook name as useSyncExternalStore and the store property that registers listeners as subscribe.
const myStore = {
subscribe(callback) {
// register callback; return an unsubscribe function
return () => {};
},
getSnapshot() {
return 0;
}
};
function Counter() {
const count = **useSyncExternalStore**(
myStore.**subscribe**,
myStore.getSnapshot
);
return <div>{count}</div>;
}
The React 18+ hook for external stores is useSyncExternalStore, and it is called with a subscribe function followed by a getSnapshot function. In the given myStore object, the method that registers a listener is named subscribe, so the second blank is subscribe, and the call becomes useSyncExternalStore(myStore.subscribe, myStore.getSnapshot). Because the store defines its listener registration as subscribe in the code shown, that name is the only one that wires the component to the store correctly.
Given the following minimal external-store implementation and React component, what is logged to the console immediately after the button is clicked once?#
// See prompt above — output produced after the button click
console.log('render', value); // what value is printed?Show answer
render 1
When store.increment() is called, count becomes 1 and all registered listeners are notified. useSyncExternalStore detects that getSnapshot() now returns a different value (1 vs the previously stored 0) and synchronously re-renders the component. The console.log inside Counter therefore prints render 1. The initial render 0 was already printed on mount and is not repeated by the click.
What is the difference between state and props?#
Show answer
Props are inputs passed in by a parent and are read-only to the receiving component. State is data the component owns and can change over time (via its setter), triggering a re-render.
Data flows down as props; a component manages its own state. Lifting state up means moving shared state to a common ancestor and passing it back down as props.
In React 18, which call to useSyncExternalStore correctly subscribes to a simple client-side external store without passing a server snapshot?#
Options
Show answer
Calling useSyncExternalStore(store.subscribe, store.getSnapshot) is the correct form for a client-only external store in React 18. The first argument is the subscribe function and the second is the getSnapshot function; the third argument, getServerSnapshot, is optional and only needed for server rendering and hydration.
useSyncExternalStore takes a subscribe function first and a getSnapshot function second; getServerSnapshot is an optional third argument used only for server rendering and hydration. The question excludes that third argument, so the only valid two-argument call with the arguments in the right order is useSyncExternalStore(store.subscribe, store.getSnapshot). The call that passes the snapshot function as the first argument has its arguments swapped, and the call with only store.getSnapshot omits subscribe. The call that includes store.getServerSnapshot is excluded by the question's condition, since it supplies a server snapshot. This hook was introduced in React 18 to subscribe to external stores without tearing.
The following custom store integration with useSyncExternalStore makes React throw the development error "The result of getSnapshot should be cached to avoid an infinite loop". Identify the buggy line.#
const store = {
items: ['apple', 'banana'],
listeners: [],
subscribe(cb) {
this.listeners.push(cb);
return () => { this.listeners = this.listeners.filter(l => l !== cb); };
},
getSnapshot() {
return [...this.items];
},
addItem(item) {
this.items = [...this.items, item];
this.listeners.forEach(l => l());
},
};
function ItemList() {
const items = useSyncExternalStore(store.subscribe.bind(store), store.getSnapshot.bind(store));
return <ul>{items.map(i => <li key={i}>{i}</li>)}</ul>;
}Show answer
The bug is on line 9.
The buggy statement is on line 9, return [...this.items];, inside getSnapshot. Spreading creates a new array object on every call, so two consecutive calls with no data change still return values that fail Object.is. React's useSyncExternalStore compares successive snapshots with Object.is and, seeing a different reference each time, keeps re-reading the store until it gives up and throws the 'should be cached' error in development. The fix is to return the same cached array until items actually changes, for example by updating a cached snapshot inside addItem and having getSnapshot return that stored reference.
What problem does the Context API solve, and what is the tradeoff of using it?#
Show answer
Context lets a Provider supply a value to any descendant via useContext, avoiding prop drilling through intermediate components that don't need the data. The tradeoff is that every consumer re-renders when the context value changes, so an unstable or overly broad value can cause widespread re-renders.
Context targets prop drilling — passing data deep through components that only forward it. The cost is that changing the provided value re-renders all consumers, so split or memoize context values to limit that.
Which of the following statements about useSyncExternalStore (React 18+) is correct?#
Options
Show answer
A getSnapshot function that returns a new object on every call, even when the store has not changed, makes React re-render endlessly and fail with 'Maximum update depth exceeded'. React compares snapshots with Object.is, so the returned value must be cached between calls while the underlying data is unchanged.
React compares snapshots with Object.is on every render. If getSnapshot returns a new object each time without the store changing, the comparison always reports a change, so React schedules another render, which again gets a new object. In development React also logs a console.error warning that the result of getSnapshot should be cached, but the render loop itself ends in a 'Maximum update depth exceeded' error. The statement about the new reference is therefore the correct one. The third argument is only optional for client-only rendering; omitting it during server rendering or hydration throws a missing getServerSnapshot error, so the claim that it never errors is false. Requiring a Context Provider is false because the hook takes a subscribe function and a getSnapshot function directly and needs no provider. The Redux-only claim is false because the hook works with any external store, including browser APIs such as navigator.onLine.
The hook below uses useSyncExternalStore with a custom store. Assume this store API: store.subscribe(listener) registers the listener and returns an unsubscribe function that removes that same listener when called. store.getSnapshot() returns a cached value whose identity changes only when the store's state actually changes. The subscribe function is memoized with useCallback, so its identity is stable across renders. Assume useCallback and useSyncExternalStore are imported from react. Exactly one line contains a statement that causes a listener to leak. Identify that line (counting from 1, with the function line as line 1).#
function useCustomStore(store) {
const subscribe = useCallback((callback) => {
store.subscribe(callback);
}, [store]);
return useSyncExternalStore(subscribe, () => store.getSnapshot());
}Show answer
The bug is on line 3.
The bug is on line 3, the statement store.subscribe(callback);. Under the stated store API, store.subscribe returns an unsubscribe function, but this statement discards it, so the subscribe callback passed to useSyncExternalStore returns undefined. React needs the returned function so it can remove the listener on unmount or when subscribe changes, so the listener is never removed and accumulates. The fix is return store.subscribe(callback);. Line 2 only opens the memoized arrow function and line 4 only closes it with its dependency array, so neither contains the statement that drops the handle. Line 5 is correct under the stated contract, because getSnapshot returns a cached value with stable identity, and the subscribe identity is stable because of useCallback.
React's concurrent renderer can cause tearing, where different components reading an external store see inconsistent values within one render. Select all statements that correctly describe how useSyncExternalStore detects store changes and avoids tearing.#
Options
Pick every one that applies.
Show answer
The correct statements are: useSyncExternalStore re-checks the store before committing a concurrent render and re-renders synchronously if the snapshot changed, and getSnapshot must return the same reference while the store is unchanged. React relies on Object.is to detect changes, so a stable cached snapshot is required. Store updates are not batched through setState, and React does not ignore mid-render changes.
useSyncExternalStore reads the store through getSnapshot during render. Before committing a concurrent render, React calls getSnapshot again for each store and compares the result with the value the render used via Object.is. If they differ, the render is thrown away and redone synchronously, so no tear is committed. The statement about the snapshot returning a stable reference is also correct: Object.is comparison only detects changes if an unchanged store yields the identical cached value, which is why the snapshot (not the store object's internal structure) must be immutable. The batching statement is wrong because store updates are not routed through setState. The statement about ignoring changes is wrong because React detects the change and re-renders rather than ignoring it.
Sources
The official documentation these questions are checked against:
Related interview questions
Job market
See react salaries and hiring demand from live job postings.
The other 15 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 15 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback