2025-05-12 13:19:05 +00:00
|
|
|
import * as React from "react";
|
2025-03-03 06:51:13 +00:00
|
|
|
|
2025-05-12 13:19:05 +00:00
|
|
|
const MOBILE_BREAKPOINT = 768;
|
2025-03-03 06:51:13 +00:00
|
|
|
|
|
|
|
export function useIsMobile() {
|
2025-05-12 13:19:05 +00:00
|
|
|
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
|
|
|
|
undefined
|
|
|
|
);
|
2025-03-03 06:51:13 +00:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
2025-05-12 13:19:05 +00:00
|
|
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
2025-03-03 06:51:13 +00:00
|
|
|
const onChange = () => {
|
2025-05-12 13:19:05 +00:00
|
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
|
|
};
|
|
|
|
mql.addEventListener("change", onChange);
|
|
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
|
|
return () => mql.removeEventListener("change", onChange);
|
|
|
|
}, []);
|
2025-03-03 06:51:13 +00:00
|
|
|
|
2025-05-12 13:19:05 +00:00
|
|
|
return !!isMobile;
|
2025-03-03 06:51:13 +00:00
|
|
|
}
|