Skip to content

Commit

Permalink
refactor: add accesibility feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Oct 23, 2024
1 parent 67502d2 commit cf333b9
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import { useEffect, useState } from 'react';

export default function useAnimateOnce (condition: boolean | undefined): boolean {
const [animate, setAnimate] = useState(false);
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

useEffect((): void => {
if (condition) {
useEffect(() => {
if (condition && !prefersReducedMotion) {
setAnimate(true);

setTimeout(() => setAnimate(false), 500);
const timeoutId = setTimeout(() => setAnimate(false), 500);

return () => clearTimeout(timeoutId);
}
}, [condition]);

return undefined;
}, [condition, prefersReducedMotion]);

return animate;
}

0 comments on commit cf333b9

Please sign in to comment.