BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/zyeon/use-media-query

useMediaQuery

zyeon/use-media-query
FreeHook

An SSR-safe hook that subscribes to a CSS media query and returns whether it currently matches.

Install it

npx shadcn@latest add https://ui.zyeon.ai/r/use-media-query.json

Source

src/registry/hooks/use-media-query.tsxui.zyeon.ai/r/use-media-query.json
1"use client"
2
3import * as React from "react"
4
5export interface UseMediaQueryOptions {
6 /** Snapshot used during SSR and before hydration. Defaults to false. */
7 serverFallback?: boolean
8}
9
10/**
11 * Subscribe to a CSS media query and return whether it currently matches.
12 * `useSyncExternalStore` wires `matchMedia`, an external data source, into the
13 * React tree: subscribe attaches the `change` listener of `matchMedia(query)`,
14 * getSnapshot reads `.matches`, and getServerSnapshot returns `serverFallback`
15 * while rendering on the server. All three are new closures whenever `query`
16 * changes, so a changing `query` unsubscribes from the old `matchMedia` and
17 * subscribes to the new one on its own — no hand-written `useEffect`, no
18 * dependency array, and no `setState` in an effect body.
19 *
20 * `useReducedMotion` in this repo's `animated-text.tsx` is this hook specialised
21 * to a single query (`prefers-reduced-motion: reduce`) with `serverFallback`
22 * pinned to `false`.
23 */
24export function useMediaQuery(query: string, options: UseMediaQueryOptions = {}): boolean {
25 const { serverFallback = false } = options
26
27 const subscribe = React.useCallback(
28 (callback: () => void) => {
29 if (typeof window === "undefined") return () => {}
30 const mql = window.matchMedia(query)
31 mql.addEventListener("change", callback)
32 return () => mql.removeEventListener("change", callback)
33 },
34 [query],
35 )
36
37 const getSnapshot = React.useCallback(() => window.matchMedia(query).matches, [query])
38 const getServerSnapshot = React.useCallback(() => serverFallback, [serverFallback])
39
40 return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
41}
42
43export default useMediaQuery

Files it writes

  • src/registry/hooks/use-media-query.tsx

Facts

Registry
zyeon
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-13
Last confirmed
today

Go to the source

ui.zyeon.ai Zyeon-AI/zyeon-ui-components on GitHub Raw registry item This item as JSON

More from zyeon

All 893 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useAsyncuse-asynczyeonHooksFreeno deps
useBatteryuse-batteryzyeonHooksFreeno deps
useBroadcastChanneluse-broadcast-channelzyeonHooksFreeno deps
useClickOutsideuse-click-outsidezyeonHooksFreeno deps
useClipboardPasteuse-clipboard-pastezyeonHooksFreeno deps
useControllableStateuse-controllable-statezyeonHooksFreeno deps
useCookieuse-cookiezyeonHooksFreeno deps
useCopyToClipboarduse-copy-to-clipboardzyeonHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex