Answers for "window resize next js"

0

window resize next js

const useWidth = () => {
    const [width, setWidth] = useState(0); // default width, detect on server.
    const handleResize = () => setWidth(window.innerWidth);
    useEffect(() => {
      window.addEventListener('resize', handleResize);
      return () => window.removeEventListener('resize', handleResize);
    }, [handleResize]);
    return width;
};
Posted by: Guest on August-23-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language