From 3c04ca840f9a5747f7b0090bba27fb1c92e5dd16 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 9 Feb 2025 09:54:17 -0600 Subject: [PATCH] Stop checking for window in useEffect --- src/utility/useIsDesktop.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/utility/useIsDesktop.ts b/src/utility/useIsDesktop.ts index 729c6639..2e58ba89 100644 --- a/src/utility/useIsDesktop.ts +++ b/src/utility/useIsDesktop.ts @@ -4,18 +4,16 @@ export default function useIsDesktop() { const [isDesktop, setIsDesktop] = useState(); useEffect(() => { - if (typeof window !== 'undefined') { - const breakpointMd = getComputedStyle(document.body) - .getPropertyValue('--breakpoint-md'); - const mql = window.matchMedia(`(min-width: ${breakpointMd})`); - setIsDesktop(mql.matches); + const breakpointMd = getComputedStyle(document.body) + .getPropertyValue('--breakpoint-md'); + const mql = window.matchMedia(`(min-width: ${breakpointMd})`); + setIsDesktop(mql.matches); - const eventHandler = (event: MediaQueryListEvent) => - setIsDesktop(event.matches); + const eventHandler = (event: MediaQueryListEvent) => + setIsDesktop(event.matches); - mql.addEventListener('change', eventHandler); - return () => mql.removeEventListener('change', eventHandler); - } + mql.addEventListener('change', eventHandler); + return () => mql.removeEventListener('change', eventHandler); }, []); return isDesktop;