mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
@alexgleason pointed out aspect ratio would break screens that were physically wide but not quite the shape 11/9 expects
20 lines
592 B
TypeScript
20 lines
592 B
TypeScript
import { useEffect, useState } from "react"
|
|
|
|
const MOBILE_BREAKPOINT = 1080;
|
|
|
|
export function useIsMobile(): boolean {
|
|
const [isMobile, setIsMobile] = useState(window.innerWidth < MOBILE_BREAKPOINT);
|
|
|
|
useEffect(() => {
|
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
const onChange = () => {
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
}
|
|
mql.addEventListener("change", onChange);
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
return () => mql.removeEventListener("change", onChange);
|
|
}, []);
|
|
|
|
return !!isMobile;
|
|
}
|