snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
14
apps/v4/registry/bases/base/hooks/_registry.ts
Normal file
14
apps/v4/registry/bases/base/hooks/_registry.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { type Registry } from "shadcn/schema"
|
||||
|
||||
export const hooks: Registry["items"] = [
|
||||
{
|
||||
name: "use-mobile",
|
||||
type: "registry:hook",
|
||||
files: [
|
||||
{
|
||||
path: "hooks/use-mobile.ts",
|
||||
type: "registry:hook",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
19
apps/v4/registry/bases/base/hooks/use-mobile.ts
Normal file
19
apps/v4/registry/bases/base/hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
Reference in New Issue
Block a user