Created
July 22, 2018 14:21
-
-
Save zerobias/bbed4555c9447e683d3433c01ca8487f to your computer and use it in GitHub Desktop.
Scroll to top component
This file contains hidden or 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 { Component } from 'react'; | |
import { withRouter } from 'react-router'; | |
class ScrollToTop extends Component { | |
componentDidUpdate(prevProps) { | |
if (this.props.location !== prevProps.location) { | |
window.scrollTo(0, 0); | |
} | |
} | |
render() { | |
return this.props.children; | |
} | |
} | |
export default withRouter(ScrollToTop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment