diff --git a/src/common/transitions/TransitionAnimation.tsx b/src/common/transitions/TransitionAnimation.tsx index 8e348497..54a4304b 100644 --- a/src/common/transitions/TransitionAnimation.tsx +++ b/src/common/transitions/TransitionAnimation.tsx @@ -1,9 +1,8 @@ -import { FC, ReactNode, useEffect, useState } from 'react'; -import { Transition } from 'react-transition-group'; -import { getTransitionAnimationStyle } from './TransitionAnimationStyles'; +import { FC, ReactNode, useEffect, useRef, useState } from "react"; +import { Transition } from "react-transition-group"; +import { getTransitionAnimationStyle } from "./TransitionAnimationStyles"; -interface TransitionAnimationProps -{ +interface TransitionAnimationProps { type: string; inProp: boolean; timeout?: number; @@ -11,42 +10,43 @@ interface TransitionAnimationProps children?: ReactNode; } -export const TransitionAnimation: FC = props => -{ - const { type = null, inProp = false, timeout = 300, className = null, children = null } = props; +export const TransitionAnimation: FC = ({ + type, + inProp, + timeout = 300, + className = "", + children, +}) => { + const nodeRef = useRef(null); + const [isChildrenVisible, setChildrenVisible] = useState(false); - const [ isChildrenVisible, setChildrenVisible ] = useState(false); + useEffect(() => { + let timeoutId: ReturnType | null = null; - useEffect(() => - { - let timeoutData: ReturnType = null; - - if(inProp) - { + if (inProp) { setChildrenVisible(true); - } - else - { - timeoutData = setTimeout(() => - { + } else { + timeoutId = setTimeout(() => { setChildrenVisible(false); - clearTimeout(timeout); }, timeout); } - return () => - { - if(timeoutData) clearTimeout(timeoutData); + return () => { + if (timeoutId) clearTimeout(timeoutId); }; - }, [ inProp, timeout ]); + }, [inProp, timeout]); return ( - - { state => ( -
- { isChildrenVisible && children } + + {(state) => ( +
+ {isChildrenVisible && children}
- ) } + )}
); };