(query: string, device?: MediaQueryMatchers)
| 70 | } |
| 71 | |
| 72 | const useMatchMedia = (query: string, device?: MediaQueryMatchers) => { |
| 73 | const getMatchMedia = () => matchMedia(query, device || {}, !!device) |
| 74 | const [mq, setMq] = useState(getMatchMedia) |
| 75 | const isUpdate = useIsUpdate() |
| 76 | |
| 77 | useEffect(() => { |
| 78 | if (isUpdate) { |
| 79 | // skip on mounting, it has already been set |
| 80 | const newMq = getMatchMedia() |
| 81 | setMq(newMq) |
| 82 | |
| 83 | return () => { |
| 84 | if (newMq) { |
| 85 | newMq.dispose() |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | }, [query, device]) |
| 90 | |
| 91 | return mq |
| 92 | } |
| 93 | |
| 94 | const useMatches = (mediaQuery: MediaQueryList): boolean => { |
| 95 | const [matches, setMatches] = useState<boolean>(mediaQuery.matches) |
no test coverage detected
searching dependent graphs…