Skip to content

Instantly share code, notes, and snippets.

@vivmaha
Created May 5, 2017 21:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivmaha/f34fdea72d0f1fa0467a671b5ec7321e to your computer and use it in GitHub Desktop.
Save vivmaha/f34fdea72d0f1fa0467a671b5ec7321e to your computer and use it in GitHub Desktop.
import * as React from "react";
import { RouteComponentProps, withRouter } from "react-router";
// Scroll restoration based on https://reacttraining.com/react-router/web/guides/scroll-restoration.
export var ScrollToTop = withRouter(
class ScrollToTopWithoutRouter extends React.Component<RouteComponentProps<any>, void> {
componentDidUpdate(prevProps: Readonly<RouteComponentProps<any>>) {
if (this.props.location !== prevProps.location) {
window.scrollTo(0, 0)
}
}
render(): JSX.Element {
return null;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment