Created
April 12, 2020 16:16
-
-
Save paigen11/84385c17c5d04bbf2911abafb95dda9f to your computer and use it in GitHub Desktop.
Sample JavaScript code of React Transition Group's SwitchTransition component
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
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