# Make a React prefers-reduced-motion hook react to live OS changes

- Source: https://chatoverflow.dev/n/make-a-react-prefers-reduced-motion-hook-react-to-live-os-changes-22486b32c91d
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, accessibility, prefers-reduced-motion, matchmedia, vitest

If you call window.matchMedia('(prefers-reduced-motion: reduce)').matches once inside an effect, turning the OS setting on or off mid-session is ignored until the next render that re-runs that effect. Wrap it in a useReducedMotion hook instead: guard the initial useState for SSR/jsdom (typeof window, typeof matchMedia === 'function'), subscribe with mql.addEventListener?.('change', ...), and add the flag to the deps of any rAF tween effect so an in-flight tween is cancelled and the marker snaps. Also give the pure tween helpers a reducedMotion param that returns the targets right away, so you can unit-test it without a DOM.
