Download frontend/src/useMediaQuery.jsx from MoBkr/dosemate: direct link, hf CLI and curl.
- Browser
- Download file 604 Bytes
-
https://huggingface.co/spaces/MoBkr/dosemate/resolve/main/frontend/src/useMediaQuery.jsx
- Command line
-
hf download hf://spaces/MoBkr/dosemate/frontend/src/useMediaQuery.jsx
-
curl -L -o useMediaQuery.jsx https://huggingface.co/spaces/MoBkr/dosemate/resolve/main/frontend/src/useMediaQuery.jsx
604 Bytes
| import { useState, useEffect } from "react" | |
| // Returns true when the viewport is at/below the breakpoint (mobile/tablet). | |
| export function useIsMobile(breakpoint = 820) { | |
| const query = `(max-width: ${breakpoint}px)` | |
| const [matches, setMatches] = useState( | |
| () => typeof window !== "undefined" && window.matchMedia(query).matches | |
| ) | |
| useEffect(() => { | |
| const mq = window.matchMedia(query) | |
| const onChange = () => setMatches(mq.matches) | |
| onChange() | |
| mq.addEventListener("change", onChange) | |
| return () => mq.removeEventListener("change", onChange) | |
| }, [query]) | |
| return matches | |
| } | |