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

The Performance Cost of useLayoutEffect

Understanding how useLayoutEffect blocks painting and when this tradeoff is worth it.

The Performance Cost of useLayoutEffect

You'll learn why useLayoutEffect can slow down your app and when that tradeoff makes sense.

The Blocking Behavior

useLayoutEffect runs synchronously after React updates the DOM but before the browser paints. This means it blocks the browser from showing anything to the user until your effect finishes executing.

Think of it like a checkout line: useLayoutEffect is that one customer asking complex questions while everyone behind them waits. The cashier (browser) can't serve the next person (paint to screen) until the current transaction completes.

Comparing the Timeline

With useEffect:

  1. React updates DOM
  2. Browser paints (user sees changes immediately)
  3. Effect runs

With useLayoutEffect:

  1. React updates DOM
  2. Layout effect runs (browser waits)
  3. Browser paints (user sees changes only after effect finishes)

The Performance Impact

If your layout effect takes 50ms to run, that's 50ms where:

  • The screen is frozen
  • User interactions don't register
  • The app feels laggy

For every re-render that triggers your useLayoutEffect, you're adding that synchronous delay. Multiply that across frequent updates (like form inputs or animations), and the app becomes noticeably sluggish.

When the Cost is Worth It

Use useLayoutEffect only when the visual flicker from useEffect would be jarring or confusing—like measuring DOM elements before positioning a tooltip or preventing a flash of unstyled content. The brief performance hit is better than a broken user experience.

For everything else, stick with useEffect and let the browser paint freely.

Key Takeaway: useLayoutEffect blocks painting and slows down your app, so reserve it strictly for cases where measuring or mutating layout before paint is essential to avoid visual bugs.