Initial commit
This commit is contained in:
16
src/hooks/useReducedMotion.ts
Normal file
16
src/hooks/useReducedMotion.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export function useReducedMotion(): boolean {
|
||||
const [reducedMotion, setReducedMotion] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia('(prefers-reduced-motion: reduce)')
|
||||
setReducedMotion(mq.matches)
|
||||
|
||||
const handler = (e: MediaQueryListEvent) => setReducedMotion(e.matches)
|
||||
mq.addEventListener('change', handler)
|
||||
return () => mq.removeEventListener('change', handler)
|
||||
}, [])
|
||||
|
||||
return reducedMotion
|
||||
}
|
||||
Reference in New Issue
Block a user