mirror of
https://github.com/prymitive/karma
synced 2026-05-09 03:36:44 +00:00
chore(ui): migrate more code to typescript
This commit is contained in:
committed by
Łukasz Mierzwa
parent
55170f8812
commit
4d4dd111c1
42
ui/src/Hooks/useFlashTransition.ts
Normal file
42
ui/src/Hooks/useFlashTransition.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user