BrowserBeginnerSSR-safehooks/browser/useReducedMotion.ts

useReducedMotion

prefers-reduced-motion.

Import

TypeScript
import { useReducedMotion } from '@/hooks';

API

Signature

useReducedMotion(default?) → boolean

When to use

Use useReducedMotion instead of re-implementing the same pattern in multiple components.

SSR / Next.js

Returns defaults on the server; hydrates on the client.

Live playground

Edit the example and see it run against the real @/hooks package in this app.

Live playgroundEdit · run with real @/hooks · useReducedMotion
Editor
function Motion() {
  const reduce = useReducedMotion();
  return <div data-reduce-motion={reduce}>…</div>;
}
Preview

Implementation source

Full library source for useReducedMotion — copy into your project when you are not installing a package yet.

hooks/browser/useReducedMotion.ts
import { useMediaQuery } from './useMediaQuery';

/** Respects `prefers-reduced-motion`. */
export function useReducedMotion(defaultValue = false): boolean {
  return useMediaQuery('(prefers-reduced-motion: reduce)', defaultValue);
}

Copy-paste example

useReducedMotion.example.tsx
'use client';

import { useReducedMotion } from '@/hooks';

export function Motion() {
  const reduce = useReducedMotion();
  return <div data-reduce-motion={reduce}>…</div>;
}

Production checklist

  • Called only from Client Components or other custom hooks
  • Type parameters filled in (e.g. useFetch<User[]>)
  • Tip: Values are safe during SSR (defaults). Gate layout-dependent UI with useMounted when needed.
  • Source of truth: open hooks/browser/useReducedMotion.ts for implementation details