Files
ai-agent/web/hooks/use-lg-media.ts
T

26 lines
710 B
TypeScript
Raw Normal View History

2026-04-09 10:01:23 +08:00
"use client";
import { useSyncExternalStore } from "react";
2026-05-25 12:06:15 +08:00
/** Matches Tailwind's default `lg` breakpoint (1024px). */
2026-04-09 10:01:23 +08:00
const LG_MEDIA_QUERY = "(min-width: 1024px)";
function subscribe(onStoreChange: () => void) {
const mq = window.matchMedia(LG_MEDIA_QUERY);
mq.addEventListener("change", onStoreChange);
return () => mq.removeEventListener("change", onStoreChange);
}
function getSnapshot() {
return window.matchMedia(LG_MEDIA_QUERY).matches;
}
function getServerSnapshot() {
return false;
}
2026-05-25 12:06:15 +08:00
/** Client-only true at lg and above. SSR always returns false for mobile-first rendering. */
2026-04-09 10:01:23 +08:00
export function useIsLgUp() {
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}