mango-v4-ui/hooks/useViewport.tsx

19 lines
626 B
TypeScript
Raw Normal View History

2023-08-31 19:23:53 -07:00
import mangoStore from '@store/mangoStore'
import { useMemo } from 'react'
import { breakpoints } from 'utils/theme'
2022-07-14 16:36:31 -07:00
export const useViewport = () => {
2023-08-31 19:23:53 -07:00
const width = mangoStore((s) => s.window.width)
const height = mangoStore((s) => s.window.height)
2022-07-14 16:36:31 -07:00
2023-08-31 20:22:50 -07:00
const [isMobile, isTablet, isDesktop] = useMemo(() => {
if (!width) return [false, false, false]
const mobile = width < breakpoints.sm
const tablet = width >= breakpoints.sm && width < breakpoints.md
const desktop = width >= breakpoints.md
return [mobile, tablet, desktop]
2023-08-31 19:23:53 -07:00
}, [width])
2022-07-14 16:36:31 -07:00
2023-08-31 20:22:50 -07:00
return { width, height, isMobile, isTablet, isDesktop }
2022-07-14 16:36:31 -07:00
}