/
GreyCat
/
openhuman
Обзор
Документация
Войти
/
GreyCat
/
openhuman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
app/src/hooks/useMediaQuery.ts
27 строк
880 B
Steven Enamakel
feat(ui): TwoPanelLayout shell for Settings, Brain, Connections, Chat (#3643)
13 июн 2026, 06:26
Не верифицирован
13 июн 2026, 06:26
190329c
Код
Авторство
О чём код?
import { useSyncExternalStore } from 'react'; /** * Subscribes to a CSS media query and returns whether it currently matches. * SSR/test-safe: returns false when matchMedia is unavailable. */ export const useMediaQuery = (query: string): boolean => { const subscribe = (onStoreChange: () => void) => { if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') { return () => {}; } const mql = window.matchMedia(query); mql.addEventListener('change', onStoreChange); return () => mql.removeEventListener('change', onStoreChange); }; const getSnapshot = () => { if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') { return false; } return window.matchMedia(query).matches; }; return useSyncExternalStore(subscribe, getSnapshot, () => false); }; export default useMediaQuery;