window resize next js

Solutions on MaxInterview for window resize next js by the best coders in the world

showing results for - "window resize next js"
Johanna
23 Jul 2018
1const useWidth = () => {
2    const [width, setWidth] = useState(0); // default width, detect on server.
3    const handleResize = () => setWidth(window.innerWidth);
4    useEffect(() => {
5      window.addEventListener('resize', handleResize);
6      return () => window.removeEventListener('resize', handleResize);
7    }, [handleResize]);
8    return width;
9};
10