chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useMediaQuery(query: string): boolean {
|
||||
const [matches, setMatches] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
typeof window === "undefined" ||
|
||||
typeof window.matchMedia === "undefined"
|
||||
)
|
||||
return;
|
||||
const mediaQueryList = window.matchMedia(query);
|
||||
const updateMatch = () => setMatches(mediaQueryList.matches);
|
||||
updateMatch();
|
||||
mediaQueryList.addEventListener("change", updateMatch);
|
||||
return () => mediaQueryList.removeEventListener("change", updateMatch);
|
||||
}, [query]);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
export default useMediaQuery;
|
||||
Reference in New Issue
Block a user