// The pages are styled inline, where CSS media queries cannot reach. This hook // gives them the same breakpoint to branch on, driven by matchMedia so it costs // nothing per scroll or resize frame. const MOBILE_QUERY = "(max-width: 767px)"; function useMedia(query) { const [matches, setMatches] = React.useState(() => window.matchMedia(query).matches); React.useEffect(() => { const mql = window.matchMedia(query); const onChange = (e) => setMatches(e.matches); setMatches(mql.matches); mql.addEventListener("change", onChange); return () => mql.removeEventListener("change", onChange); }, [query]); return matches; } function useIsMobile() { return useMedia(MOBILE_QUERY); } Object.assign(window, { useMedia, useIsMobile, MOBILE_QUERY });