useLayoutEffect

A version of useEffect that runs synchronously after React changes the DOM but before the browser paints the screen.

In more detail

Use it to measure elements, for example with getBoundingClientRect, and adjust positions before the user sees anything, which prevents flicker. Because it blocks painting, keep it short and prefer useEffect for everything else.

Related terms

Taught in

References