Skip to content

Commit 40154c4

Browse files
authored
Update use-mobile.tsx
1 parent cb2b97d commit 40154c4

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

hooks/use-mobile.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
import * as React from "react"
2-
3-
const MOBILE_BREAKPOINT = 768
4-
5-
export function useIsMobile() {
6-
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
7-
8-
React.useEffect(() => {
9-
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
10-
const onChange = () => {
11-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
12-
}
13-
mql.addEventListener("change", onChange)
14-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
15-
return () => mql.removeEventListener("change", onChange)
16-
}, [])
17-
18-
return !!isMobile
19-
}

0 commit comments

Comments
 (0)