metis-desk/packages/rdx-ui/src/hooks/use-compact-detail.ts

20 lines
460 B
TypeScript
Raw Normal View History

2026-10-09 08:18:00 +00:00
import { useSyncExternalStore } from "react";
const COMPACT_DETAIL = "(max-width: 1099px)";
2026-10-10 10:01:58 +00:00
2026-10-09 08:18:00 +00:00
function subscribe(listener: () => void) {
const media = window.matchMedia(COMPACT_DETAIL);
2026-10-10 10:01:58 +00:00
2026-10-09 08:18:00 +00:00
media.addEventListener("change", listener);
2026-10-10 10:01:58 +00:00
2026-10-09 08:18:00 +00:00
return () => media.removeEventListener("change", listener);
}
2026-10-10 10:01:58 +00:00
export function useCompactDetail() {
2026-10-09 08:18:00 +00:00
return useSyncExternalStore(
subscribe,
() => window.matchMedia(COMPACT_DETAIL).matches,
2026-10-09 08:18:00 +00:00
() => false
);
}