34 lines
734 B
TypeScript
34 lines
734 B
TypeScript
|
import { useEffect, useState } from "react";
|
||
|
|
||
|
interface ScreenSize {
|
||
|
width: number | undefined;
|
||
|
height: number | undefined;
|
||
|
}
|
||
|
|
||
|
export default function useWindowSize(): number {
|
||
|
const [windowSize, setWindowSize] = useState<ScreenSize>({
|
||
|
width: undefined,
|
||
|
height: undefined,
|
||
|
});
|
||
|
|
||
|
useEffect(() => {
|
||
|
function handleResize() {
|
||
|
setWindowSize({
|
||
|
width: window.innerWidth,
|
||
|
height: window.innerHeight,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
window.addEventListener("resize", handleResize);
|
||
|
|
||
|
handleResize();
|
||
|
|
||
|
return () => window.removeEventListener("resize", handleResize);
|
||
|
}, []);
|
||
|
if(typeof(windowSize.width) === "number") {
|
||
|
return windowSize.width <= 1080 ? 1 : 0;
|
||
|
}
|
||
|
else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|