Top React Interview Questions and Answers
The React interview questions asked most often, with clear answers on the virtual DOM, keys, state, hooks, useEffect and performance.
React interviews test whether you understand how React thinks, not just its syntax. These are the questions asked most often, with answers you can explain clearly and code to back them up.
1. What is the virtual DOM and how does reconciliation work?#
The virtual DOM is a lightweight JavaScript description of the UI. When state changes, React builds a new tree, compares it with the previous one (reconciliation or "diffing"), and updates only the parts of the real DOM that changed.
2. Why do lists need keys?#
Keys tell React which item is which between renders, so it can reorder, add or remove items correctly. Use a stable, unique ID. Using the array index causes bugs when items are reordered or deleted, such as input values jumping to the wrong row.
{todos.map(todo => (
<TodoItem key={todo.id} todo={todo} />
))}3. What is the difference between state and props?#
Props are passed into a component from its parent and are read-only. State is data a component owns and can change with its setter. When either changes, the component re-renders.
4. Why doesn't state update immediately?#
State updates are scheduled, not applied instantly, and React batches them for performance. Reading state right after setting it gives the old value. When the new value depends on the old one, use the updater function.
// Wrong: adds 1, not 3
setCount(count + 1);
setCount(count + 1);
setCount(count + 1);
// Right: adds 3
setCount(c => c + 1);
setCount(c => c + 1);
setCount(c => c + 1);5. Explain the useEffect dependency array#
- No array: runs after every render.
- Empty array
[]: runs once after the first render. [a, b]: runs whenaorbchanges.
Return a cleanup function to remove listeners, timers or subscriptions.
useEffect(() => {
const id = setInterval(tick, 1000);
return () => clearInterval(id);
}, []);6. When should you use useMemo and useCallback?#
useMemo caches a computed value. useCallback caches a function. Use them for genuinely expensive calculations, or to keep references stable when passing props to components wrapped in React.memo. Wrapping everything adds overhead without benefit.
7. What are controlled and uncontrolled components?#
In a controlled component, React state holds the input's value and updates it on every change. In an uncontrolled component, the DOM holds the value and you read it with a ref when needed. Controlled inputs make validation and dynamic UI easier.
// Controlled
<input value={name} onChange={e => setName(e.target.value)} />
// Uncontrolled
<input ref={inputRef} defaultValue="Asha" />8. What is prop drilling and how do you avoid it?#
Prop drilling is passing props through many layers of components that don't use them. Avoid it with the Context API for shared data like theme or user, component composition (passing components as children), or a state library like Redux or Zustand for complex app state.
9. What are the rules of hooks?#
- Only call hooks at the top level, never inside loops, conditions or nested functions.
- Only call hooks from React function components or custom hooks.
React relies on hooks being called in the same order on every render to match each hook with its stored state.
Interviewers often follow up with "build a custom hook." Practise writing useFetch or useDebounce from scratch.
Key takeaways#
- Explain reconciliation and why keys matter. They show you understand rendering.
- Use the updater function when new state depends on old state.
- Don't over-memoize. Explain when useMemo and useCallback actually help.