Skip to main content
useLayoutEffect is identical to useEffect, but it fires synchronously after all DOM mutations and before the browser has a chance to paint. Use this to read layout from the DOM and synchronously re-render.

Signature

Parameters

() => void | (() => void)
required
A function containing imperative, possibly effectful code. Can optionally return a cleanup function that will be called before the effect runs again or when the component unmounts.
ReadonlyArray<unknown>
An array of dependencies. The effect will only re-run if one of the values in this array has changed (compared using ===). If omitted, the effect runs after every render.

Returns

void

Basic Usage

Preventing Flash of Incorrect Content

Synchronizing with DOM Mutations

Reading Layout Properties

Focus Management

Measuring and Positioning

Performance Warning: useLayoutEffect runs synchronously and blocks the browser from painting. This can hurt performance if used excessively. Prefer useEffect when possible.
Use useLayoutEffect when you need to:
  • Read layout from the DOM (measurements, positions)
  • Mutate the DOM synchronously before paint
  • Prevent visual flicker or “flash of incorrect content”
Updates scheduled inside useLayoutEffect will be flushed synchronously, after all DOM mutations but before the browser paints.