Created
January 28, 2018 22:01
-
-
Save elisechant/c328395070e52c7cdeba175c43cf8508 to your computer and use it in GitHub Desktop.
React page transitions - CSS Transition - react-transition-group v1, react router v4
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 React from 'react'; | |
import { Route } from "react-router-dom"; | |
import TransitionGroup from "react-transition-group/TransitionGroup"; | |
import TransitionedPage from './transitionedPage'; | |
const HomePage = () => <div>Home</div> | |
const ContactPage = () => <div>Contact</div> | |
const App = () => { | |
return ( | |
<div className="App"> | |
<TransitionGroup> | |
<Route path="/" exact component={TransitionedPage(HomePage)}/> | |
<Route path="/contact" exact component={TransitionedPage(ContactPage)}/> | |
</TransitionGroup> | |
</div> | |
) | |
}; |
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 React from 'react'; | |
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup'; | |
import './style.css'; | |
const TransitionedPage = WrappedComponent => | |
class TransitionedPage extends React.Component { | |
render() { | |
return ( | |
<CSSTransitionGroup | |
transitionName="example" | |
transitionAppear={true} | |
transitionAppearTimeout={500} | |
transitionEnter={false} | |
transitionLeave={false}> | |
<WrappedComponent {...this.props} /> | |
</CSSTransitionGroup> | |
); | |
} | |
}; | |
export default TransitionedPage; |
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
.example-appear { | |
opacity: 0.01; | |
} | |
.example-appear.example-appear-active { | |
opacity: 1; | |
transition: opacity .5s ease-in; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment