The Render-Commit-Effect Timeline Visualized
What you'll learn: How to trace a complete update from a setState call all the way through render, commit, paint, and effects in exact sequence.
The Complete Journey of a State Update
When you call setState, React orchestrates a carefully choreographed sequence of phases. Let's trace the exact timeline:
1. Trigger (setState Called)
You call setState in an event handler or effect. This schedules an update—nothing visual happens yet.
2. Render Phase (Pure Calculation)
React calls your component function to calculate what the UI should look like. This creates a new virtual DOM tree. Multiple setState calls might batch here, resulting in a single render.
3. Commit Phase (DOM Updates)
React compares the new virtual DOM with the previous one and applies only the necessary changes to the actual DOM. This is fast but still invisible to the user.
4. Browser Paint
The browser takes the updated DOM and paints pixels to the screen. Now the user sees the change.
5. Effects Phase (Side Effects Run)
After the paint completes, React runs your useEffect callbacks. This ensures effects never block visual updates. (useLayoutEffect runs before paint, synchronously.)
Mental Model: The Assembly Line
Think of it like a factory assembly line:
- Render = blueprint drawn
- Commit = parts assembled
- Paint = product packaged
- Effects = shipped to customer
Each phase must complete before the next begins. Effects always run after the user sees the update, which is why they can't cause visual flicker (unlike useLayoutEffect).
Key Takeaway: Every state update flows through render → commit → paint → effects in strict order, with effects always running after the user sees the change.