mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-28 23:24:13 +00:00
* feat(v4): upgrade calendar * feat: more calendar examples * fix: remove grid * feat: more examples * feat: more examples * fix * feat: update examples * fix: dark mode * fix: calendar in dark mode * fix: examples * fix * docs: update calendar docs * feat: update cmdk * fix: block viewer patterns * feat: update new-york and default * fix: docs and examples * fix: command menu * feat: remove blocks from cmdk * fix * fix: calendar 13 * fix: format * fix * feat: update calendar default
18 lines
553 B
TypeScript
18 lines
553 B
TypeScript
import * as React from "react"
|
|
|
|
export function useIsMobile(mobileBreakpoint = 768) {
|
|
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
|
|
|
React.useEffect(() => {
|
|
const mql = window.matchMedia(`(max-width: ${mobileBreakpoint - 1}px)`)
|
|
const onChange = () => {
|
|
setIsMobile(window.innerWidth < mobileBreakpoint)
|
|
}
|
|
mql.addEventListener("change", onChange)
|
|
setIsMobile(window.innerWidth < mobileBreakpoint)
|
|
return () => mql.removeEventListener("change", onChange)
|
|
}, [])
|
|
|
|
return !!isMobile
|
|
}
|