React · Middle · Question 64 of 75
How do you measure an element's size right after it renders, before the browser paints?
- ✓Correct answer: Read it in
useLayoutEffect(e.g. to position a tooltip) and set state there - 2Read it during render
- 3Read it in
useEffect- it always runs before paint
Explanation
useLayoutEffect blocks painting until it finishes, avoiding a visible jump. Use it sparingly; it doesn't run on the server.