mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-27 07:52:11 -05:00
24 lines
607 B
TypeScript
24 lines
607 B
TypeScript
import { useEffect, useState } from "preact/hooks";
|
|
|
|
export function useWindowSize() {
|
|
const [windowSize, setWindowSize] = useState({
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
});
|
|
|
|
useEffect(() => {
|
|
function handleResize() {
|
|
setWindowSize({
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
});
|
|
}
|
|
|
|
window.addEventListener("resize", handleResize);
|
|
handleResize();
|
|
|
|
return () => window.removeEventListener("resize", handleResize);
|
|
}, []);
|
|
|
|
return windowSize;
|
|
}
|