Download src/hooks/use-media-query.tsx from web-zero/ui: direct link, hf CLI and curl.
- Browser
- Download file 465 Bytes
-
https://huggingface.co/spaces/web-zero/ui/resolve/main/src/hooks/use-media-query.tsx
- Command line
-
hf download hf://spaces/web-zero/ui/src/hooks/use-media-query.tsx
-
curl -L -o use-media-query.tsx https://huggingface.co/spaces/web-zero/ui/resolve/main/src/hooks/use-media-query.tsx
465 Bytes
| import * as React from "react"; | |
| export function useMediaQuery(query: string) { | |
| const [value, setValue] = React.useState(false); | |
| React.useEffect(() => { | |
| function onChange(event: MediaQueryListEvent) { | |
| setValue(event.matches); | |
| } | |
| const result = matchMedia(query); | |
| result.addEventListener("change", onChange); | |
| setValue(result.matches); | |
| return () => result.removeEventListener("change", onChange); | |
| }, [query]); | |
| return value; | |
| } | |