Solution 1:

Use can use this it work. useEffect(didUpdate);. Accepts a function that contains imperative, possibly effectful code.

const App = () => {
    useEffect(() => {
        const width = document.getElementById('width').clientWidth;
        console.log({ width });
    }, []);
    
   return(
            <div id="width" />
   );
}