File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,20 +2,27 @@ import { useSyncExternalStore } from "react"
22
33const MOBILE_BREAKPOINT = 768
44
5- const mql = window . matchMedia ( `(max-width: ${ MOBILE_BREAKPOINT - 1 } px)` )
5+ const mql =
6+ typeof window !== "undefined"
7+ ? window . matchMedia ( `(max-width: ${ MOBILE_BREAKPOINT - 1 } px)` )
8+ : null
69
710function mediaQueryListener ( callback : ( event : MediaQueryListEvent ) => void ) {
8- mql . addEventListener ( "change" , callback )
11+ mql ? .addEventListener ( "change" , callback )
912
1013 return ( ) => {
11- mql . removeEventListener ( "change" , callback )
14+ mql ? .removeEventListener ( "change" , callback )
1215 }
1316}
1417
1518function isSmallerThanBreakpoint ( ) {
16- return mql . matches
19+ return mql ! . matches
1720}
1821
1922export function useIsMobile ( ) {
20- return useSyncExternalStore ( mediaQueryListener , isSmallerThanBreakpoint )
23+ return useSyncExternalStore (
24+ mediaQueryListener ,
25+ isSmallerThanBreakpoint ,
26+ ( ) => false ,
27+ )
2128}
You can’t perform that action at this time.
0 commit comments