diff --git a/src/lib/useMediaQuery.tsx b/src/lib/useMediaQuery.tsx index df1efdd..84c945a 100644 --- a/src/lib/useMediaQuery.tsx +++ b/src/lib/useMediaQuery.tsx @@ -6,12 +6,9 @@ const useMediaQuery = (query: string) => { useEffect(() => { const media = window.matchMedia(query); - if (media.matches !== matches) { - setMatches(media.matches); - } - const listener = () => { - setMatches(media.matches); - }; + if (media.matches !== matches) setMatches(media.matches); + const listener = () => setMatches(media.matches); + media.addEventListener("change", listener); return () => media.removeEventListener("change", listener); }, [matches, query]);