Cachy / website /lib /useReducedMotion.ts
Vatxzz's picture
added the website for app.
32f7b59
Raw
History Blame Contribute Delete
647 Bytes
"use client";
import { useEffect, useState } from "react";
/**
* Tracks `prefers-reduced-motion`. Returns true when the visitor wants
* reduced motion — components use this to render the final static state.
*/
export function usePrefersReducedMotion(): boolean {
const [reduced, setReduced] = useState(false);
useEffect(() => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
setReduced(mq.matches);
const onChange = (e: MediaQueryListEvent) => setReduced(e.matches);
mq.addEventListener("change", onChange);
return () => mq.removeEventListener("change", onChange);
}, []);
return reduced;
}