Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1001 Bytes

use-reduced-motion.mdx

File metadata and controls

27 lines (20 loc) · 1001 Bytes

import { HooksDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';

export default Layout(MDX_DATA.useReducedMotion);

Usage

use-reduced-motion detects if user prefers to reduce motion. It uses use-media-query hook under the hood. Hook relies on window.matchMedia() API and will always return false if api is not available (e.g. during server side rendering), unless the initial value is provided in the first argument.

Use hook to detect if user prefers to reduce motion ((prefers-reduced-motion: reduce) media query) and set animations duration based on this value.

Definition

function useReducedMotion(
  initialValue?: boolean,
  options?: {
    getInitialValueInEffect: boolean;
  }
): boolean;