Skip to content

Instantly share code, notes, and snippets.

@selbekk
Created July 20, 2017 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selbekk/2b996c3ced6f073a50788cc35aff2026 to your computer and use it in GitHub Desktop.
Save selbekk/2b996c3ced6f073a50788cc35aff2026 to your computer and use it in GitHub Desktop.
Scroll to top after react-router navigation
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