Added undefined Size state to useWindowsize

This commit is contained in:
Neshura 2022-12-09 18:28:23 +01:00
parent 9cba3c50c9
commit df0326f9ff
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A

View file

@ -1,9 +1,14 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
export default function useWindowSize() { interface ScreenSize {
const [windowSize, setWindowSize] = useState({ width: number | undefined;
width: 0, height: number | undefined;
height: 0, }
export default function useWindowSize(): boolean | undefined {
const [windowSize, setWindowSize] = useState<ScreenSize>({
width: undefined,
height: undefined,
}); });
useEffect(() => { useEffect(() => {
@ -20,5 +25,10 @@ export default function useWindowSize() {
return () => window.removeEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize);
}, []); }, []);
if(typeof(windowSize.width) === "number") {
return windowSize.width <= 1080; return windowSize.width <= 1080;
}
else {
return undefined;
}
} }