'use client' /** * Is this a phone-width viewport? * * A media query rather than a user-agent string: what a layout needs to know is * how much room it has, and a narrow window on a desktop wants the same answer * as a phone does. 768px is the `md` breakpoint the rest of the package uses. * * Starts `false` on the server, where there is no viewport to ask, and corrects * on mount — so the markup is the desktop one and hydration does not mismatch. */ import { useEffect, useState } from 'react' const PHONE = '(max-width: 767px)' export function useIsMobile(): boolean { const [narrow, setNarrow] = useState(false) useEffect(() => { const q = window.matchMedia(PHONE) const read = () => setNarrow(q.matches) read() q.addEventListener('change', read) return () => q.removeEventListener('change', read) }, []) return narrow } export default useIsMobile