Something went wrong. Try again.
Fork of backnotprop/plannotator with reduced surface area
Something went wrong. Try again.
123456789101112131415161718import { useState, useEffect } from 'react';
export function useIsMobile(breakpoint = 768): boolean { const [isMobile, setIsMobile] = useState( () => typeof window !== 'undefined' ? window.innerWidth < breakpoint : false );
useEffect(() => { const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`); const onChange = (e: MediaQueryListEvent) => setIsMobile(e.matches); mql.addEventListener('change', onChange); setIsMobile(mql.matches); return () => mql.removeEventListener('change', onChange); }, [breakpoint]);
return isMobile;}