Run a layout-sensitive effect before the browser paints.
Section: Effect Hooks
useLayoutEffect before paint
tsx
tsx
useLayoutEffect(() => {
inputRef.current?.focus();
}, []);Explanation
Reserve `useLayoutEffect` for measurement or layout-sensitive updates; prefer `useEffect` by default.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Effect Hooks
Fetch inside an effect
Fetch client-side data in an effect with cleanup guard.
useEffectEvent for non-reactive effect logic
Read latest values in an effect event without re-triggering the effect.