React Render vs Commit Phase: How React Updates UI

🚀 React Render vs Commit Phase — How React Actually Updates UI Most developers know: 👉 React re-renders components But what really happens behind the scenes? 👉 React works in two phases 💡 1. Render Phase (Calculation Phase) 👉 React prepares what needs to change ✔ Creates new Virtual DOM ✔ Compares with previous tree (Reconciliation) ✔ Decides what to update ❗ No DOM updates happen here 💡 2. Commit Phase (Execution Phase) 👉 React applies the changes to the real DOM ✔ Updates DOM ✔ Runs useEffect ✔ Updates refs 👉 This is where UI actually changes ⚙️ Flow (Step-by-step) 1️⃣ State/props change 2️⃣ Render Phase runs (diffing) 3️⃣ React calculates changes 4️⃣ Commit Phase updates DOM 🧠 Why this matters 👉 React separates thinking from doing: Render Phase → “What to update?” Commit Phase → “Apply updates” 🔥 Important Behavior ✔ Render phase can run multiple times ✔ Commit phase runs once per update 👉 This enables features like: Concurrent rendering Interruptible updates ⚠️ Common Mistake // ❌ Side effects in render const data = fetchData(); 👉 Causes bugs → should be inside useEffect 🔥 Best Practices ✅ Keep render phase pure ✅ Avoid side effects in render ✅ Use useEffect for side effects ❌ Don’t trigger DOM changes in render 💬 Pro Insight (Senior-Level Thinking) 👉 Render phase can be paused, restarted, or discarded 👉 Commit phase is always final 📌 Save this post & follow for more deep frontend insights! 📅 Day 23/100 #ReactJS #FrontendDevelopment #JavaScript #ReactInternals #PerformanceOptimization #SoftwareEngineering #100DaysOfCode 🚀

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories