Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/thatstupidcomputer / apps/web/src/animation/core/useMedia.ts |
| Date | Not specified in source |
| Repository | Janady13/thatstupidcomputer |
| Revision | 57555cde46910102dd25d6c1c1fb2c359e9655bd |
| Branch | main |
| Path or archive member | apps/web/src/animation/core/useMedia.ts |
| Original SHA-256 | a1dbdb4a9299c681b2c94d917f4f0e2ba958339aacc90b2803dad202f73d2c68 |
| Git blob SHA | c78d384d4b9cb037d73bb82db3716d205a33e3f2 |
| Reading-copy SHA-256 | a1dbdb4a9299c681b2c94d917f4f0e2ba958339aacc90b2803dad202f73d2c68 |
Recovered source transcript
Download complete source text ↓13 lines · 0.5 KB
'use client';
import { useEffect, useState } from 'react';
/** Deterministic server value avoids hydration disagreement. */
export function useMedia(query: string, serverValue = false): boolean {
const [matches, set] = useState(serverValue);
useEffect(() => {
const media = window.matchMedia(query); const update = () => set(media.matches);
update(); media.addEventListener('change', update);
return () => media.removeEventListener('change', update);
}, [query]);
return matches;
}