React · Frontend system thinking
How does the virtual DOM and reconciliation work?
Short answer
React builds a tree of elements describing the UI, compares it with the previous tree, and applies the necessary DOM changes. That diffing process is reconciliation.
A React element is a lightweight object describing what should appear. On each render, React creates a new tree. It then compares the new tree with the previous one and updates only the parts whose type, position or key changed.
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
);
}The diffing heuristics
- Different element types cause React to unmount the old subtree and mount a new one
- Same element type keeps the DOM node and updates changed attributes
- Lists use keys to match items across renders
- React compares siblings by position when keys are absent
The virtual DOM is not automatically faster than careful direct DOM work. Its value is that it lets you write declarative code while React batches and minimises updates. React's Fiber architecture makes rendering interruptible and supports concurrent features.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What are React's reconciliation heuristics?
- 2Why do keys matter during reconciliation?
- 3Is the virtual DOM faster than the real DOM?
- 4What is React Fiber?
Say it in the interview
React renders a tree of elements that describes the UI. On the next render it compares the new tree with the previous one, using element type, position and keys to decide what can be reused. It then applies only the necessary DOM changes. That diffing is reconciliation. The virtual DOM is mainly a programming model, not a guarantee of speed, and Fiber makes the work interruptible for concurrent rendering.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.