Created component to scroll to top

This commit is contained in:
Alejandro Celaya
2018-08-05 11:20:09 +02:00
parent ad29e2fa5d
commit ec6b11d9c9
2 changed files with 26 additions and 1 deletions

22
src/common/ScrollToTop.js Normal file
View File

@@ -0,0 +1,22 @@
import React from 'react';
import { withRouter } from 'react-router-dom'
export class ScrollToTop extends React.Component {
componentDidUpdate(prevProps) {
const { location, window } = this.props;
if (location !== prevProps.location) {
window.scrollTo(0, 0)
}
}
render() {
return this.props.children;
}
}
ScrollToTop.defaultProps = {
window
};
export default withRouter(ScrollToTop);