HookfoundationsLabs examplesMIT
useReducedMotion
A hook that reports whether the user prefers reduced motion and updates when the setting changes.
Not yet available: this combination has no tested variant yet. Pick another option above.
Install
Item use-reduced-motion · registry JSON
npx shadcn@latest add https://labs.designfrom.com/r/use-reduced-motion.jsonnpx shadcn@latest add @designfrom/use-reduced-motionOnce, in components.json: "registries": { "@designfrom": "https://labs.designfrom.com/r/{name}.json" }
npm i @designfrom/reactimport { useReducedMotion } from "@designfrom/react/use-reduced-motion";Source
Comments are kept. The header lists provenance, license and install commands for people and coding assistants.
"use client";
import * as React from "react";
/**
* @dfl-header: v1, generated by labs.designfrom.com at build time
* Item: use-reduced-motion (useReducedMotion)
* What: A hook that reports whether the user prefers reduced motion and
* updates when the setting changes.
* Status: ready. License: MIT. Author: Design From Labs
* <https://labs.designfrom.com>
* Source: https://github.com/Design-from-labs/labs @ 803b92c1a30e (examples/use-reduced-motion)
* Credits: S-003 React (MIT); S-004 shadcn/ui and its registry schema (MIT)
* Install: npx shadcn@latest add https://labs.designfrom.com/r/use-reduced-motion.json
* npx shadcn@latest add @designfrom/use-reduced-motion
* npm i @designfrom/react, then import { useReducedMotion } from "@designfrom/react/use-reduced-motion";
* Docs: https://labs.designfrom.com/ui/use-reduced-motion (index: https://labs.designfrom.com/llms.txt)
*/
const QUERY = "(prefers-reduced-motion: reduce)";
function subscribe(onChange: () => void) {
const media = window.matchMedia(QUERY);
media.addEventListener("change", onChange);
return () => media.removeEventListener("change", onChange);
}
/**
* true when the user prefers reduced motion. Server rendering assumes false;
* the browser value takes over on hydration and follows later changes.
*/
export function useReducedMotion(): boolean {
return React.useSyncExternalStore(
subscribe,
() => window.matchMedia(QUERY).matches,
() => false,
);
}Dependencies
- None.
Usage
const reduceMotion = useReducedMotion();Props
| Prop | Type | Default | Description |
|---|---|---|---|
| returns | boolean | true when the user prefers reduced motion; false during server rendering. |
Accessibility
- Use it to skip or shorten JavaScript-driven motion; CSS motion should use motion-safe and motion-reduce instead.
Credits
- React · Meta Platforms and contributors · MIT
- shadcn/ui and its registry schema · shadcn · MIT
License and source
- License
- MIT
- Author
- Design From Labs <https://labs.designfrom.com>
- Source
- github.com/Design-from-labs/labs
- Commit
- 803b92c1a30e
- Date
- 2026-10-12
- Origin
- labs-examples