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