From df0326f9ff73d3b2d96d08f6cdefbf80f4051471 Mon Sep 17 00:00:00 2001 From: Neshura Date: Fri, 9 Dec 2022 18:28:23 +0100 Subject: [PATCH] Added undefined Size state to useWindowsize --- components/windowsize.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/components/windowsize.tsx b/components/windowsize.tsx index 27cb575..063fae5 100644 --- a/components/windowsize.tsx +++ b/components/windowsize.tsx @@ -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({ + 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; + } } \ No newline at end of file