You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vinibiavatti1 edited this page Sep 28, 2026
·
4 revisions
A version of useEffect that fires synchronously before the browser repaints the screen. Use it to read layout from the DOM and synchronously re-render before the user sees the visual update.
Note: Has the exact same signature as useEffect (accepts a dependency array and returns a cleanup function).
import{useRef,useLayoutEffect}from'react';exportconstComponent=()=>{constboxRef=useRef(null);useLayoutEffect(()=>{constwidth=boxRef.current?.offsetWidth;// Update UI before render...},[]);// ...};