blob: 21e5c1f0d2ea3eb443fa7d9f7a7c2f92a92e2e57 [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001import * as React from "react";
gio5f2f1002025-03-20 18:38:48 +04002
giod0026612025-05-08 13:00:36 +00003const MOBILE_BREAKPOINT = 768;
gio5f2f1002025-03-20 18:38:48 +04004
5export function useIsMobile() {
giod0026612025-05-08 13:00:36 +00006 const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
gio5f2f1002025-03-20 18:38:48 +04007
giod0026612025-05-08 13:00:36 +00008 React.useEffect(() => {
9 const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
10 const onChange = () => {
11 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
12 };
13 mql.addEventListener("change", onChange);
14 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
15 return () => mql.removeEventListener("change", onChange);
16 }, []);
gio5f2f1002025-03-20 18:38:48 +040017
giod0026612025-05-08 13:00:36 +000018 return !!isMobile;
gio5f2f1002025-03-20 18:38:48 +040019}