void/utils/shared/hooks/useWindowSize.ts
2022-10-19 23:59:59 +02:00

15 lines
No EOL
497 B
TypeScript

import { useLayoutEffect, useState } from "react";
const useWindowSize = () => {
const [windowSize, setWindowSize] = useState({ width: 0, height: 0 })
const handleSize = () => setWindowSize({ width: window.innerWidth, height: window.innerHeight })
useLayoutEffect(() => {
handleSize()
window.addEventListener("resize", handleSize);
return () => window.removeEventListener("resize", handleSize);
}, [])
return windowSize
}
export default useWindowSize