Course contentsShow
← React
Lesson 529 of 2,39615. useEffect FundamentalsFree lesson

When useEffect Runs: After Commit

Learn that effects run after React commits changes to the DOM, not during render.

When useEffect Runs: After Commit

What you'll learn: You'll understand the precise moment useEffect executes in React's lifecycle—after the DOM has been updated, not during the rendering phase.

The Timing of useEffect

When you use useEffect, React doesn't run your effect code immediately during render. Instead, it waits until after the commit phase—the moment when React has finished updating the actual DOM and the browser has painted those changes to the screen.

Here's the sequence:

  1. Render phase: React calculates what needs to change
  2. Commit phase: React applies those changes to the DOM
  3. Paint: The browser displays the updates on screen
  4. Effect phase: useEffect callbacks run

Why This Matters

This timing is crucial because it means:

  • The DOM is fully updated when your effect runs
  • Users can already see the new UI
  • Your effects won't block the visual update
  • You can safely read DOM properties or measurements

Think of it like cooking: React first plates the food (commits to the DOM), serves it to the customer (browser paints), and then cleans up the kitchen (runs effects). The customer doesn't have to wait for cleanup before eating.

The Guarantee

By the time your useEffect code executes, you're guaranteed that:

  • All state updates have been applied
  • The DOM reflects the current component state
  • Refs point to the actual DOM nodes
  • The user can see and interact with the updated UI

This "after commit" timing is what makes useEffect safe for side effects like data fetching, subscriptions, or manual DOM manipulations—none of these operations delay what the user sees.

Key Takeaway: useEffect runs after React commits changes to the DOM and the browser paints, ensuring your side effects never block visual updates or run with stale DOM state.