файл пакета→ .shtukbase/packages/keer-ui/library/hooks/use-mobile.ts
library/hooks/use-mobile.ts
22 строки, 662 Б.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- import * as React from "react";
- // The phone width is the same as `--breakpoint-phone` in styles/tokens.css.
- const MOBILE_BREAKPOINT = 560;
- export function useIsMobile() {
- const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
- undefined,
- );
- React.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;
- }