Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
549 B · 20 lines
TypeScript
123456789101112131415161718192021import { useEffect, useState } from "react";
const MOBILE_BREAKPOINT = 768;
export function useIsMobile(): boolean { const [isMobile, setIsMobile] = useState<boolean>(() => { if (typeof window === "undefined") return false; return window.innerWidth < MOBILE_BREAKPOINT; });
useEffect(() => { const onResize = () => { setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); }; window.addEventListener("resize", onResize); return () => window.removeEventListener("resize", onResize); }, []);
return isMobile;}