This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
scoresaber-reloadedv3/src/hooks/use-window-dimensions.ts

27 lines
592 B
TypeScript
Raw Normal View History

2024-09-11 20:26:24 +00:00
import { useEffect, useState } from "react";
function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height,
};
}
export default function useWindowDimensions() {
2024-09-13 12:45:04 +00:00
const [windowDimensions, setWindowDimensions] = useState(
getWindowDimensions(),
);
2024-09-11 20:26:24 +00:00
useEffect(() => {
function handleResize() {
setWindowDimensions(getWindowDimensions());
}
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
return windowDimensions;
}