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";
|
||||
|
||||
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);
|
||||
}, []);
|
||||
if(typeof(windowSize.width) === "number") {
|
||||
return windowSize.width <= 1080;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
Reference in a new issue