Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created July 22, 2018 14:21
Show Gist options
  • Save zerobias/bbed4555c9447e683d3433c01ca8487f to your computer and use it in GitHub Desktop.
Save zerobias/bbed4555c9447e683d3433c01ca8487f to your computer and use it in GitHub Desktop.
Scroll to top component
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