Update formatting of useMediaQuery.tsx

This commit is contained in:
Bastian Meissner 2021-11-26 21:16:10 +01:00
parent fcd99434a0
commit 9c76a43144

View file

@ -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]);