1const [width, setWidth] = useState(window.innerWidth);
2const [height, setHeight] = useState(window.innerHeight);
3const updateDimensions = () => {
4 setWidth(window.innerWidth);
5 setHeight(window.innerHeight);
6}
7useEffect(() => {
8 window.addEventListener("resize", updateDimensions);
9 return () => window.removeEventListener("resize", updateDimensions);
10}, []);
11