Created
May 5, 2017 21:05
-
-
Save vivmaha/f34fdea72d0f1fa0467a671b5ec7321e to your computer and use it in GitHub Desktop.
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
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