feat: basic initial UI layout for mobile and desktop
This commit is contained in:
19
apps/web/src/hooks/useIsMobile.ts
Normal file
19
apps/web/src/hooks/useIsMobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
const MOBILE_QUERY = '(max-width: 1023px)'
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = useState(
|
||||
() => typeof window !== 'undefined' && window.matchMedia(MOBILE_QUERY).matches,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const mql = window.matchMedia(MOBILE_QUERY)
|
||||
const handleChange = (event: MediaQueryListEvent) => setIsMobile(event.matches)
|
||||
setIsMobile(mql.matches)
|
||||
mql.addEventListener('change', handleChange)
|
||||
return () => mql.removeEventListener('change', handleChange)
|
||||
}, [])
|
||||
|
||||
return isMobile
|
||||
}
|
||||
Reference in New Issue
Block a user