2026-10-09 08:18:00 +00:00
|
|
|
import { useSyncExternalStore } from "react";
|
|
|
|
|
|
2026-10-15 10:12:53 +00:00
|
|
|
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) {
|
2026-10-15 10:12:53 +00:00
|
|
|
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
|
|
|
|
2026-10-15 10:12:53 +00:00
|
|
|
export function useCompactDetail() {
|
2026-10-09 08:18:00 +00:00
|
|
|
return useSyncExternalStore(
|
|
|
|
|
subscribe,
|
2026-10-15 10:12:53 +00:00
|
|
|
() => window.matchMedia(COMPACT_DETAIL).matches,
|
2026-10-09 08:18:00 +00:00
|
|
|
() => false
|
|
|
|
|
);
|
|
|
|
|
}
|