QuizNot attempted
Measuring the DOM before paint
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
useLayoutEffectruns synchronously after DOM mutations but before the browser paints, preventing a visible flicker when adjusting layout based on measured DOM size
useLayoutEffectruns after DOM mutations but before paint, so measuring and callingsetTopre-renders synchronously and the user never sees the box in the wrong position.- Not 'runs before render': it runs after commit, like all effects.
- Not 'no difference': with
useEffectthe first paint showsmarginTop: 0, then a visible jump. - Not 'required with useRef': refs work with any effect.