Understanding React Re-renders: Virtual DOM, Diffing & Reconciliation

Understanding React Re-renders: Virtual DOM, Diffing & Reconciliation
We're all afraid of re-renders. But is this fear justified? Learn how React actually handles changes under the hood and why not every render is a disaster.
Mohammad Alhabil
Author
Understanding React Re-renders: Virtual DOM, Diffing & Reconciliation
We're all afraid of the word "re-render" — as if it's a curse that affects performance and ruins the user experience.
But... is this fear justified? Or is the problem that we don't understand what's happening under the hood?
Today, let me explain simply, with a bit of depth, how React actually handles changes — and why not every render should be considered a "danger" or "disaster."
🚀 The Story from the Beginning
When React does a re-render, it doesn't mean it's rebuilding the entire page. No!
Here's what actually happens:
| Step | What Happens |
|---|---|
| 1️⃣ | Creates a new copy of the Virtual DOM |
| 2️⃣ | Compares it with the previous version (Diffing) |
| 3️⃣ | Only updates changes to the Real DOM (Reconciliation) |
Why This Matters
The real DOM is very slow. Every time you modify it, the browser might do:
- Reflow: Recalculates positions and sizes of elements
- Repaint: Redraws pixels on the screen
React tries to avoid this scenario as much as possible... and relies on you to help it work smartly.
👨💻 How to Help React as a Developer
1. Understand When Re-render Happens
Re-renders occur when:
- ✅ Props or state changes
- ✅ Shared context value changes
- ✅ Parent re-renders (usually pulling children with it)
2. Use Tools to Reduce Unnecessary Renders
React.memo
Prevents re-render if props haven't changed:
const MyComponent = React.memo(({ data }) => {
return <div>{data.title}</div>;
});
useCallback & useMemo
Stabilize heavy values and functions:
// Memoize a function
const handleClick = useCallback(() => {
doSomething(id);
}, [id]);
// Memoize a computed value
const expensiveValue = useMemo(() => {
return computeExpensiveValue(data);
}, [data]);
⚠️ Warning: Don't use them randomly. If overused, they can actually hurt performance!
Smart Keys in Lists
// ❌ Bad - using index as key
{posts.map((post, index) => (
<Post key={index} data={post} />
))}
// ✅ Good - using unique identifier
{posts.map((post) => (
<Post key={post.id} data={post} />
))}
Using key={index} can make React redraw the entire list even if only one item changed!
Solution: Give each element a stable, unique key like post.id. This way React knows exactly what changed and only updates that.
🧠 Debugging Tool: React Profiler
The Profiler is a diagnostic tool inside React DevTools that shows:
- 📊 Which components are re-rendering
- 🔢 How many times they rendered
- ⏱️ How long each render took
- ❓ What caused the render (state? props? context?)
How to Use It
- Install React DevTools browser extension
- Open DevTools → "Profiler" tab
- Click "Record" → Interact with your app → Stop recording
- Analyze the flame graph
Pro Tip: As soon as your project grows, open the Profiler, look for bottlenecks, and start optimizing from there.
🎯 Key Takeaways
| Concept | What to Remember |
|---|---|
| Re-renders | Not always dangerous, but know why they happen |
| Smart Keys | Help React do Reconciliation accurately |
| Profiler | Helps you understand, not solve |
| Internal Phases | Virtual DOM → Diffing → Reconciliation |
The more you understand the internal phases, the cleaner, faster, and smarter code you can write.
The Flow Visualized
State/Props Change
↓
Virtual DOM (New)
↓
Diffing
(Compare with old)
↓
Reconciliation
(Update only changes)
↓
Real DOM
(Minimal updates)
Start understanding the UI, not just building it.
Interfaces you love, code you understand. 💡
Topics covered
Found this article helpful?
Share it with your network and help others learn too!

Written by Mohammad Alhabil
Frontend Developer & Software Engineer passionate about building beautiful and functional web experiences. I write about React, Next.js, and modern web development.
Related Articles
View all
Props vs State vs Context vs Ref: When to Use Each in React
Confused about when to use Props, State, Context, or Ref? Misusing them doesn't just slow performance—it creates tangled code that's hard to debug. Let's clear things up once and for all.

Managing SVG Icons in React & Next.js: The Complete Guide
Icons from different sources? Legacy SVGs as images? Learn how to properly manage, organize, and use SVG icons in modern React and Next.js projects.

Why useState Isn't Always the Answer: URL State vs React State
There's a simple pattern that can change how you handle UI, achieve better performance, maintain SEO, and create a cleaner interface. Learn when to use URL instead of useState.