From 993b5ece9ce9c9c4c2d0d1d990f724fffe0a89c7 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Fri, 19 Sep 2025 00:37:11 +0530 Subject: [PATCH] switch back to width breakpoint for useMobileView @alexgleason pointed out aspect ratio would break screens that were physically wide but not quite the shape 11/9 expects --- src/hooks/useIsMobile.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/hooks/useIsMobile.tsx b/src/hooks/useIsMobile.tsx index df4e515d..41c1df6c 100644 --- a/src/hooks/useIsMobile.tsx +++ b/src/hooks/useIsMobile.tsx @@ -1,19 +1,17 @@ import { useEffect, useState } from "react" -const ASPECT_RATIO = '11/9'; -const makeMql = () => window.matchMedia(`(max-aspect-ratio: ${ASPECT_RATIO})`); +const MOBILE_BREAKPOINT = 1080; export function useIsMobile(): boolean { - const [isMobile, setIsMobile] = useState(makeMql().matches); + const [isMobile, setIsMobile] = useState(window.innerWidth < MOBILE_BREAKPOINT); useEffect(() => { - const mql = makeMql(); - + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); const onChange = () => { - setIsMobile(mql.matches); + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); } mql.addEventListener("change", onChange); - setIsMobile(mql.matches); + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); return () => mql.removeEventListener("change", onChange); }, []);