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 b85116d commit 33d301aCopy full SHA for 33d301a
resources/js/hooks/use-mobile.tsx
@@ -6,15 +6,15 @@ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
6
7
function mediaQueryListener(callback: (event: MediaQueryListEvent) => void) {
8
mql.addEventListener('change', callback);
9
+
10
return () => {
11
mql.removeEventListener('change', callback);
12
};
13
}
14
15
export function useIsMobile() {
16
return useSyncExternalStore(
- mediaQueryListener, // React won't resubscribe for as long as you pass the same function
17
- () => window.innerWidth < MOBILE_BREAKPOINT, // How to get the value on the client
18
- () => false, // How to get the value on the server
+ mediaQueryListener,
+ () => window.innerWidth < MOBILE_BREAKPOINT,
19
);
20
0 commit comments