SPB Git

Repository Public

hooks.ts 757 B 18 lines typescript

1import { useSyncExternalStore } from "react";23const noop = () => () => {};4/** False during server rendering and hydration, true afterwards — without a state update in an effect. */5export function useHydrated(): boolean {6  return useSyncExternalStore(noop, () => true, () => false);7}89function subscribeMotion(cb: () => void): () => void {10  const mq = window.matchMedia("(prefers-reduced-motion: reduce)");11  mq.addEventListener("change", cb);12  return () => mq.removeEventListener("change", cb);13}14/** The reader asked the system for less motion. False on the server. */15export function useReducedMotion(): boolean {16  return useSyncExternalStore(subscribeMotion, () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, () => false);17}18
Files main
Menu

Theme