2022-09-25 23:43:53 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-09-16 15:28:39 +00:00
|
|
|
|
2022-09-25 23:43:53 +00:00
|
|
|
export function useIsMobile(threshold?: number) {
|
|
|
|
const [isMobile, setIsMobile] = useState<boolean>()
|
|
|
|
useEffect(() => {
|
|
|
|
// 640 matches tailwind sm breakpoint
|
|
|
|
const onResize = () => setIsMobile(window.innerWidth < (threshold ?? 640))
|
|
|
|
onResize()
|
|
|
|
window.addEventListener('resize', onResize)
|
|
|
|
return () => window.removeEventListener('resize', onResize)
|
|
|
|
}, [threshold])
|
|
|
|
return isMobile
|
2022-09-16 15:30:09 +00:00
|
|
|
}
|