mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
* feat: upgrade to Next.js 16 * chore: deps * fix * fix * fix * fix: workaround zod 4 for now * fix * fix: copy button * fix: update apps/v4/hooks/use-is-mac.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix * fix: remove --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
18 lines
569 B
TypeScript
18 lines
569 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)
|
|
}, [mobileBreakpoint])
|
|
|
|
return !!isMobile
|
|
}
|