Created
July 20, 2017 06:33
-
-
Save selbekk/2b996c3ced6f073a50788cc35aff2026 to your computer and use it in GitHub Desktop.
Scroll to top after react-router navigation
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 { PureComponent } from 'react'; | |
import { withRouter } from 'react-router-dom'; | |
class ScrollToTop extends PureComponent { | |
componentDidUpdate = ({ location }) => location !== this.props.location && window.scrollTo(0, 0); | |
render = () => null; | |
} | |
export default withRouter(ScrollToTop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment