0.1.5 • Published 3 years ago
unmount-animation-clone v0.1.5
UnmountAnimationClone (React Component)
A simple utility component that clones the DOM element for animation before it unmounts.
Installation
yarn add unmount-animation-cloneUsage
Style
@keyframes animation-enter {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes animation-leave {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.animated-element {
animation-duration: 0.5s;
animation-name: animation-enter;
}
.animated-element.unmount {
/* Unmount animation is required. */
animation-name: animation-leave;
}Render
import {useEffect, useState} from 'react';
import {UnmountAnimationClone} from 'unmount-animation-clone';
function App() {
let [shown, setShown] = useState();
useEffect(() => {
let timer = setTimeout(() => setShown(!shown), 2000);
return () => clearTimeout(timer);
}, [shown]);
return shown ? (
<UnmountAnimationClone>
<div className="animated-element">hello, world!</div>
</UnmountAnimationClone>
) : (
<></>
);
}API References
UnmountAnimationClone
classNameclass name adds to the DOM element clone for unmount animation, defaults tounmount.
UnmountAnimationClonerequires one and only one React element as child. If the child is not a DOM element, make sureforwardRefis used to forward the ref to the outermost DOM element.
UnmountAnimationClonerelies onanimationendevent to remove the animated clone, so unmount animation is required.
License
MIT License.