MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / useMediaQuery

Function useMediaQuery

ui/src/App.tsx:22–34  ·  view source on GitHub ↗

Subscribe to a CSS media query, SSR-safe (defaults to matched).

(query: string)

Source from the content-addressed store, hash-verified

20
21/** Subscribe to a CSS media query, SSR-safe (defaults to matched). */
22function useMediaQuery(query: string): boolean {
23 const [matches, setMatches] = useState(() =>
24 typeof window !== 'undefined' ? window.matchMedia(query).matches : true,
25 )
26 useEffect(() => {
27 const mq = window.matchMedia(query)
28 const handler = () => setMatches(mq.matches)
29 setMatches(mq.matches) // re-sync in case the query changed between renders
30 mq.addEventListener('change', handler)
31 return () => mq.removeEventListener('change', handler)
32 }, [query])
33 return matches
34}
35
36/**
37 * Three breakpoints drive the responsive shell:

Callers 2

useIsDesktopFunction · 0.85
useIsRoomyFunction · 0.85

Calls 1

addEventListenerMethod · 0.65

Tested by

no test coverage detected