Skip to content

Instantly share code, notes, and snippets.

@paigen11
Created April 12, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paigen11/84385c17c5d04bbf2911abafb95dda9f to your computer and use it in GitHub Desktop.
Save paigen11/84385c17c5d04bbf2911abafb95dda9f to your computer and use it in GitHub Desktop.
Sample JavaScript code of React Transition Group's SwitchTransition component
const App = () => {
const [state, setState] = React.useState(true);
return (
<>
<div className="main">
<SwitchTransition mode={'in-out'}>
<CSSTransition
key={state}
addEndListener={(node, done) => {
node.addEventListener("transitionend", done, false);
}}
classNames="fade"
>
<div className="button-container">
<Button onClick={() => setState(!state)}>
{state ? "Hello, world!" : "Goodbye, world!"}
</Button>
</div>
</CSSTransition>
</SwitchTransition>
</div>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment