mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-23 21:22:04 -05:00
23 lines
682 B
TypeScript
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,
|
|
);
|
|
}
|