Open this example in the interactive library
Live preview
Source code
// components/ReducedMotionPreferenceLabel.tsx
import { useState, useEffect } from "react";
export default function ReducedMotionPreferenceLabel({
label = "Workspace",
}: { label?: string } = {}) {
const [reduced, set] = useState(false);
useEffect(() => {
const media = matchMedia("(prefers-reduced-motion: reduce)");
const sync = () => set(media.matches);
sync();
media.addEventListener("change", sync);
return () => media.removeEventListener("change", sync);
}, []);
return (
<span>
{label}: {reduced ? "Reduced motion" : "Standard motion"}
</span>
);
}
