diff -r 000000000000 -r 5f4fcbc80b37 clientjs/packages/dashboard-components/src/ui/ScrollToTop.jsx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clientjs/packages/dashboard-components/src/ui/ScrollToTop.jsx Fri Sep 14 17:57:34 2018 +0200 @@ -0,0 +1,30 @@ +import { Component } from 'react'; +import { withRouter } from 'react-router'; +import PropTypes from 'prop-types'; + +class ScrollToTop extends Component { + componentDidUpdate(prevProps) { + const { location } = this.props; + + if (location !== prevProps.location) { + window.scrollTo(0, 0); + } + } + + render() { + const { children } = this.props; + return children; + } +} + +ScrollToTop.propTypes = { + location: PropTypes.object, + children: PropTypes.node, +}; + +ScrollToTop.defaultProps = { + location: null, + children: null, +}; + +export default withRouter(ScrollToTop);