Spaces:
Running
Running
Download frontend/src/shared/hooks/useMediaQuery.ts from Shadowfilebot/Bot: direct link, hf CLI and curl.
- Browser
- Download file 543 Bytes
-
https://huggingface.co/spaces/Shadowfilebot/Bot/resolve/main/frontend/src/shared/hooks/useMediaQuery.ts
- Command line
-
hf download hf://spaces/Shadowfilebot/Bot/frontend/src/shared/hooks/useMediaQuery.ts
-
curl -L -o useMediaQuery.ts https://huggingface.co/spaces/Shadowfilebot/Bot/resolve/main/frontend/src/shared/hooks/useMediaQuery.ts
543 Bytes
| 'use client'; | |
| import { useEffect, useState } from 'react'; | |
| export function useMediaQuery(query: string): boolean { | |
| const [matches, setMatches] = useState(false); | |
| useEffect(() => { | |
| if (typeof window === 'undefined' || !window.matchMedia) return; | |
| const mql = window.matchMedia(query); | |
| setMatches(mql.matches); | |
| const onChange = (e: MediaQueryListEvent) => setMatches(e.matches); | |
| mql.addEventListener('change', onChange); | |
| return () => mql.removeEventListener('change', onChange); | |
| }, [query]); | |
| return matches; | |
| } | |