Created
May 27, 2020 16:25
-
-
Save jonshipman/bf618d170327aa67f7fe6e34b7996e8f to your computer and use it in GitHub Desktop.
Scroll to top on internal navigation | React 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
// React Component | |
// Navigation within app will scroll to top. | |
import { Component } from 'react'; | |
import { withRouter } from 'react-router-dom'; | |
class ScrollToTop extends Component { | |
componentDidUpdate(prevProps) { | |
if (this.props.location !== prevProps.location) { | |
window.scrollTo(0, 0); | |
} | |
} | |
render() { | |
return null; | |
} | |
} | |
export default withRouter(ScrollToTop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment