chore(ui): migrate more code to typescript

This commit is contained in:
Łukasz Mierzwa
2020-06-29 16:14:53 +01:00
committed by Łukasz Mierzwa
parent 55170f8812
commit 4d4dd111c1
36 changed files with 392 additions and 205 deletions

View File

@@ -0,0 +1,42 @@
import { useState, useEffect, useRef } from "react";
import { TransitionProps } from "react-transition-group/Transition";
import { useInView } from "react-intersection-observer";
const defaultProps: TransitionProps = {
in: false,
classNames: "components-animation-flash",
timeout: 800,
appear: false,
enter: false,
exit: false,
};
const useFlashTransition = (flashOn: any) => {
const mountRef = useRef(false);
const [ref, inView] = useInView();
const [isPending, setIsPending] = useState(false);
const [props, setProps] = useState(defaultProps);
useEffect(() => {
if (mountRef.current) {
setIsPending(true);
} else {
mountRef.current = true;
}
}, [flashOn]);
useEffect(() => {
setProps({
...defaultProps,
in: isPending && inView,
enter: isPending && inView,
onEntered: () => setIsPending(false),
});
}, [inView, isPending]);
return { ref, props };
};
export { useFlashTransition, defaultProps };