clientjs/packages/dashboard-components/src/ui/ScrollToTop.jsx
changeset 0 5f4fcbc80b37
equal deleted inserted replaced
-1:000000000000 0:5f4fcbc80b37
       
     1 import { Component } from 'react';
       
     2 import { withRouter } from 'react-router';
       
     3 import PropTypes from 'prop-types';
       
     4 
       
     5 class ScrollToTop extends Component {
       
     6   componentDidUpdate(prevProps) {
       
     7     const { location } = this.props;
       
     8 
       
     9     if (location !== prevProps.location) {
       
    10       window.scrollTo(0, 0);
       
    11     }
       
    12   }
       
    13 
       
    14   render() {
       
    15     const { children } = this.props;
       
    16     return children;
       
    17   }
       
    18 }
       
    19 
       
    20 ScrollToTop.propTypes = {
       
    21   location: PropTypes.object,
       
    22   children: PropTypes.node,
       
    23 };
       
    24 
       
    25 ScrollToTop.defaultProps = {
       
    26   location: null,
       
    27   children: null,
       
    28 };
       
    29 
       
    30 export default withRouter(ScrollToTop);