import { useEffect, useState } from 'react' const QUERY = '(prefers-reduced-motion: reduce)' /** True when the visitor asked the OS for reduced motion; updates if the setting changes while the page is open. */ export function usePrefersReducedMotion(): boolean { const get = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(QUERY).matches const [reduced, setReduced] = useState(get) useEffect(() => { if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return const mq = window.matchMedia(QUERY) const on = () => setReduced(mq.matches) on() mq.addEventListener('change', on) return () => mq.removeEventListener('change', on) }, []) return reduced } export default usePrefersReducedMotion