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