React › Virtual DOM & Reconciliation
What is reconciliation in React, and how does it decide what actually needs to change on the screen?
IntermediateAnswer
Reconciliation is the process React uses to compare the new virtual DOM against the previous one, figuring out the smallest set of actual changes needed to update the real page. React uses an efficient comparison algorithm that generally assumes elements of the same type in the same position are related, allowing it to update just the specific parts that actually changed rather than rebuilding everything.
// Before: <p>Hello</p>
// After: <p>Hello there</p>
// React reuses the existing <p> element and only updates its text content,
// rather than removing the old element and creating a completely new oneReal-world example A text editor component updates just the specific paragraph a user is typing into, leaving every other paragraph on the page completely untouched, thanks to React's reconciliation process correctly identifying exactly what changed.