2026-07-26 15:13:18 +07:00
|
|
|
import * as React from "react";
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
const MOBILE_BREAKPOINT = 768;
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
|
|
|
|
|
export function useIsMobile() {
|
2026-07-26 15:13:18 +07:00
|
|
|
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2026-07-26 15:13:18 +07:00
|
|
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
const onChange = () => {
|
2026-07-26 15:13:18 +07:00
|
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
|
|
|
};
|
|
|
|
|
mql.addEventListener("change", onChange);
|
|
|
|
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
|
|
|
return () => mql.removeEventListener("change", onChange);
|
|
|
|
|
}, []);
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
|
2026-07-26 15:13:18 +07:00
|
|
|
return !!isMobile;
|
feat: add UI components including Skeleton, Slider, Sonner, Spinner, Switch, Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip, and custom hook for mobile detection
2026-07-26 14:45:47 +07:00
|
|
|
}
|