sendou.ink/app/hooks/usePrefersReducedMotion.ts
Kalle 40237891d8
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
Fix logo crazy fly after visit to /plans, honor prefers-reduced-motion
2026-06-12 17:57:58 +03:00

23 lines
682 B
TypeScript

import * as React from "react";
const QUERY = "(prefers-reduced-motion: reduce)";
function subscribe(callback: () => void) {
const mediaQueryList = window.matchMedia(QUERY);
mediaQueryList.addEventListener("change", callback);
return () => mediaQueryList.removeEventListener("change", callback);
}
/**
* Returns a boolean indicating whether the user has requested reduced motion
* via the `prefers-reduced-motion` media query. Always returns `false` during
* server-side rendering and on the first client render.
*/
export function usePrefersReducedMotion() {
return React.useSyncExternalStore(
subscribe,
() => window.matchMedia(QUERY).matches,
() => false,
);
}