useMediaQuery
v1.0.1Updated 21 Jul 2026SSR-safe React hook wrapping window.matchMedia. Accepts a CSS media query string and returns whether it currently matches, re-rendering on change. Ships with breakpoint helper (useBreakpoint), pointer-type helper (useIsT
Preview
Live · 5 storiesResponsive LayoutOpen ↗
▸Why this is recommendedhookmedia-queryresponsivebreakpoint+3
useMediaQuery — responsive layout.
Recommended for+14
- ✓Conditional render by viewport
- ✓Choosing component variants per breakpoint
- ✓Respecting prefers-reduced-motion / prefers-color-scheme
- ✓Touch-vs-mouse UI affordances
Tags+6
hookmedia-queryresponsivebreakpointssrutilitylayout
Features+4
- SSR-safe (no window access during render)
- useMediaQuery(query) returns boolean
- useBreakpoint(bp) — sm / md / lg / xl / 2xl tailwind breakpoints
- useIsTouch() — coarse pointer device detection
- usePrefersDark() — color-scheme: dark
- usePrefersReducedMotion() — reduced-motion preference
- Safari < 14 addListener fallback
Not recommended for−2
- ✕CSS-only responsive styling (prefer tailwind utilities)
- ✕One-time read at mount (use window.matchMedia directly)
Install
Ask your agent, or call the MCP tool directly. The resolved bundle is written into your project.
Usage
Tick variants in the left menu — each adds a tab with that variant’s real story source, the same code the preview above renders.
Props
PropTypeRequired
queryCSS media query (e.g. "(min-width: 768px)")
yesoptions.defaultValueSSR / pre-mount fallback (default false)
—