handle current page width in react

PHOTO EMBED

Wed Jun 22 2022 08:55:02 GMT+0000 (Coordinated Universal Time)

Saved by @nimaSm #utils

const [width, setWidth] = useState<any>(getWindowSize().innerWidth);

function getWindowSize() {
    const {innerWidth, innerHeight} = window;
    return {innerWidth, innerHeight};
}

useEffect(() => {
    function handleWindowResize() {
      setWidth(getWindowSize().innerWidth);
    }

    window.addEventListener('resize', handleWindowResize);

    return () => {
      window.removeEventListener('resize', handleWindowResize);
    };
}, []);
content_copyCOPY