We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 485058b commit 5cb97b1Copy full SHA for 5cb97b1
src/hooks/useMediaQuery.js
@@ -0,0 +1,18 @@
1
+// utils/useMediaQuery.js
2
+import { useState, useEffect } from "react";
3
+
4
+export function useMediaQuery(query) {
5
+ const mediaQuery = window.matchMedia(query);
6
+ const [matches, setMatches] = useState(mediaQuery.matches);
7
8
+ useEffect(() => {
9
+ const handleResize = (event) => {
10
+ setMatches(event.matches);
11
+ };
12
13
+ mediaQuery.addEventListener("change", handleResize);
14
+ return () => mediaQuery.removeEventListener("change", handleResize);
15
+ }, [mediaQuery]);
16
17
+ return matches;
18
+}
0 commit comments