Adapting UI Animations with useReducedMotion in ReactBrief · digest for October 19
Brief≈ 1 min

Adapting UI Animations with useReducedMotion in React

When building slide-out drawers and parallax effects, it's easy to forget that sharp, sweeping motion can cause real physical discomfort for users with vestibular sensitivities. Operating systems expose a prefers-reduced-motion setting, but killing animations outright isn't the answer either—elements start snapping abruptly across the screen.

The useReducedMotion() hook from motion/react reads that OS preference and lets you swap coordinate shifts for a gentle opacity fade:

import { motion, useReducedMotion } from "motion/react";

export function Sidebar({ isOpen }: { isOpen: boolean }) {
  const shouldReduce = useReducedMotion();
  return (
    <motion.aside
      animate={{ opacity: isOpen ? 1 : 0, x: isOpen ? 0 : shouldReduce ? 0 : "-100%" }}
      transition={{ duration: shouldReduce ? 0.2 : 0.4 }}
    />
  );
}

And if you want to apply the rule across your entire component tree, there's a global provider:

import { MotionConfig } from "motion/react";

export function AppRoot({ children }: { children: React.ReactNode }) {
  return <MotionConfig reducedMotion="user">{children}</MotionConfig>;
}

Alongside recent advances like React 19.3 stabilizing the ViewTransition component and fragment refs, this pattern keeps transitions clear and legible without triggering motion sickness.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 2