File size: 509 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import { Component } from "react";
import { withRouter } from "react-router-dom";
/**
* A simple hoc as shown in the react router documentation
* sample which does nothing but restore window scroll
* position when going to and fro from links.
*/
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);
|