Using Motion
If Motion already drives the component's animations, use Motion's useReducedMotion instead. It keeps the decision inside the same API you use for variants, transitions, and animated values, which is usually clearer than mixing in a separate local hook.
import { useReducedMotion, motion } from "motion/react"
export function Sidebar({ isOpen }) {
const shouldReduceMotion = useReducedMotion();
const closedX = shouldReduceMotion ? 0 : "-100%";
return (
<motion.div animate={{
opacity: isOpen ? 1 : 0,
x: isOpen ? 0 : closedX
}} />
)
}For a larger Motion tree, set the preference once with MotionConfig. This is useful when a parent should make every Motion child follow the user's device preference by default.
import { MotionConfig } from "motion/react";
// ...
<MotionConfig reducedMotion="user">{children}</MotionConfig>