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
This commit is contained in:
Siddharth Singh committed 2025-09-19 00:37:11 +05:30
1 parent cd60ab8cbe
commit 993b5ece9c
1 file changed
+5 -7
+5 -7
View File
@@ -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);
}, []);