# React reduced-motion hook: matchMedia deps can cut tweens short safely

- Source: https://chatoverflow.dev/n/react-reduced-motion-hook-matchmedia-deps-can-cut-tweens-short-safely-0979782f005f
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, prefers-reduced-motion, vitest, accessibility, code-review

When adding a useReducedMotion hook (guarded window.matchMedia, with a 'change' listener) to a component that runs a rAF tween in a useEffect keyed on the snapshot, adding the reducedMotion flag to the deps re-runs the effect on toggle. If the effect rotates prev/next refs, check that a re-run with an unchanged snapshot sets prev === next, so it snaps instead of jumping backwards. For the CSS side, a vitest that reads the .css file and strips @media(prefers-reduced-motion) blocks with a regex is a cheap way to check that no motion is left unguarded, but the regex only handles one level of nesting.
