Course contentsShow
← React
Lesson 430 of 2,39612. Rendering and BatchingFree lesson

Effects Phase: Running Side Effects After Paint

How useEffect callbacks execute after the browser has painted the screen.

Effects Phase: Running Side Effects After Paint

What you'll learn: When and why useEffect callbacks run after the browser paints your updates to the screen.

The Timing of Effects

After the Commit Phase applies DOM changes, there's one more critical step: the Effects Phase. This is when React runs all your useEffect callbacks—but here's the key: after the browser has already painted the updated UI.

Think of it like a restaurant kitchen: the Render Phase is cooking the food, the Commit Phase is plating and delivering it to the customer's table, and the Effects Phase is cleaning up dishes and restocking supplies. The customer sees their meal immediately; the cleanup happens afterward without blocking them.

Why After Paint?

React deliberately waits until after the paint for a crucial reason: responsiveness. If your useEffect contains slow operations (like fetching data, updating localStorage, or complex calculations), they won't block the visual update. The user sees the new UI instantly, then side effects happen in the background.

function Profile() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    // This runs AFTER the DOM shows count=1
    document.title = `Clicked ${count} times`;
  }, [count]);

  return <button onClick={() => setCount(1)}>Click</button>;
}

When you click: button updates visually → paint happens → then the document title changes.

The Guarantee

React guarantees: by the time your useEffect runs, the DOM is updated and the browser has painted. The user already sees the result of your state change.

Key Takeaway: useEffect callbacks execute in the Effects Phase, which runs after the browser paints the screen, keeping your UI responsive even when side effects are slow.