34 lines
747 B
TypeScript
34 lines
747 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
interface ScreenSize {
|
|
width: number | undefined;
|
|
height: number | undefined;
|
|
}
|
|
|
|
export default function useWindowSize(): boolean | undefined {
|
|
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;
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
} |