Download client/src/hooks/useMediaQuery.tsx from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 502 Bytes
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/client/src/hooks/useMediaQuery.tsx
- Command line
-
hf download hf://spaces/Zhitomir/chat/client/src/hooks/useMediaQuery.tsx
-
curl -L -o useMediaQuery.tsx https://huggingface.co/spaces/Zhitomir/chat/resolve/main/client/src/hooks/useMediaQuery.tsx
502 Bytes
| import { useEffect, useState } from 'react'; | |
| export default function useMediaQuery(query: string) { | |
| const [matches, setMatches] = useState(false); | |
| useEffect(() => { | |
| const media = window.matchMedia(query); | |
| if (media.matches !== matches) { | |
| setMatches(media.matches); | |
| } | |
| const listener = () => setMatches(media.matches); | |
| media.addEventListener('change', listener); | |
| return () => media.removeEventListener('change', listener); | |
| }, [matches, query]); | |
| return matches; | |
| } | |