function useMediaQuery(mediaQueryString) {
const [matches, setMatches] = useState(
typeof window === 'undefined'
? false
: !!window.matchMedia(mediaQueryString).matches
)
useEffect(() => {
const mediaQueryList = window.matchMedia(mediaQueryString)
const listener = () => setMatches(!!mediaQueryList.matches)
mediaQueryList.addListener(listener)
return () => mediaQueryList.removeListener(listener)
}, [mediaQueryString])
return matches
}