Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
useEffect runs after the browser paints; useLayoutEffect runs after DOM updates but before paint, so you use it to measure layout and adjust it without a visible flicker.
Most effects, like data fetching and subscriptions, should use useEffect so they do not delay painting. useLayoutEffect runs synchronously after React updates the DOM and before the browser paints, which lets you read a size or position and immediately apply a correction, for example positioning a tooltip so it does not overflow the viewport. Because it blocks painting, heavy work in it hurts responsiveness. It also does nothing during server rendering, so components relying on it need a client-only path or a different approach.