Skip to content

Instantly share code, notes, and snippets.

@bogdanq
Last active January 7, 2020 08:07
Show Gist options
  • Save bogdanq/68dd4af581a00eea4773ce56af774832 to your computer and use it in GitHub Desktop.
Save bogdanq/68dd4af581a00eea4773ce56af774832 to your computer and use it in GitHub Desktop.
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