Last active
January 7, 2020 08:07
-
-
Save bogdanq/68dd4af581a00eea4773ce56af774832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TransitionGroup, CSSTransition } from "react-transition-group"; | |
export const TransitionComponent = ({ | |
children, | |
isAnimated, | |
classNames, | |
timeout | |
}) => ( | |
<TransitionGroup> | |
<CSSTransition | |
key={isAnimated} | |
timeout={timeout} | |
// onExited={() => console.log("exist")} | |
classNames={classNames} | |
> | |
{children} | |
</CSSTransition> | |
</TransitionGroup> | |
); | |
export const TransitionList = ({ list, timeout, classNames, children }) => ( | |
<TransitionGroup> | |
{list.map(item => ( | |
<CSSTransition | |
key={item.id} | |
timeout={timeout} | |
// onExited={() => console.log("exist")} | |
classNames={classNames} | |
> | |
{() => children(item)} | |
</CSSTransition> | |
))} | |
</TransitionGroup> | |
); | |
//Usage | |
export const App = () => { | |
const [animation, setAnimation] = React.useState(true); | |
return ( | |
<> | |
<List /> | |
<TransitionComponent | |
timeout={300} | |
classNames="title" | |
isAnimated={animation} | |
> | |
<h1>animation test</h1> | |
</TransitionComponent> | |
<button onClick={() => setAnimation(prev => !prev)}>animation</button> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment