clientjs/packages/dashboard-components/src/ui/ScrollToTop.jsx
author ymh <ymh.work@gmail.com>
Mon, 17 Sep 2018 10:47:06 +0200
changeset 5 b26c9c44dd84
parent 0 5f4fcbc80b37
permissions -rw-r--r--
correct deploy scripts and deploy tests

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);