useMediaQuerybrowser
useMediaQuery
NewSSR SAFEListens for media query changes and returns a boolean.
$ pnpm dlx shadcn@latest add @byphongphan/use-media-queryRequires
@byphongphan in components.jsonuse-media-query.tsx
Loading preview...
Installation
$ pnpm dlx shadcn@latest add @byphongphan/use-media-queryRequires
@byphongphan in components.jsonUsage
Props & Parameters
| Param | Type | Default | Description |
|---|---|---|---|
query | string | BreakpointQuery | MediaQueryInput | — | Media query string e.g. "(min-width: 1024px)" or breakpoint token like "max-md". |
Returns
| Return | Type | Description |
|---|---|---|
matches | boolean | true if current viewport matches the media query, false otherwise. Safely synchronizes on SSR. |