Added undefined Size state to useWindowsize
This commit is contained in:
parent
9cba3c50c9
commit
df0326f9ff
1 changed files with 15 additions and 5 deletions
|
@ -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);
|
||||||
}, []);
|
}, []);
|
||||||
return windowSize.width <= 1080;
|
if(typeof(windowSize.width) === "number") {
|
||||||
|
return windowSize.width <= 1080;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in a new issue