useInMobile.tsx
1 import { useEffect, useState } from "react"; 2 3 export function useInMobile(breakpoint = 640): boolean { 4 const [isMobile, setIsMobile] = useState(false); 5 6 useEffect(() => { 7 const check = () => setIsMobile(window.innerWidth < breakpoint); 8 9 check(); 10 11 window.addEventListener("resize", check); 12 13 return () => { 14 window.removeEventListener("resize", check); 15 }; 16 }, [breakpoint]); 17 18 return isMobile; 19 }