{"size": 495, "ext": "js", "max_stars_repo_path": "src/base/containers/ScrollToTop.js", "max_stars_repo_name": "dook/dofacts-panel", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/base/containers/ScrollToTop.js", "max_issues_repo_name": "dook/dofacts-panel", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/base/containers/ScrollToTop.js", "max_forks_repo_name": "dook/dofacts-panel", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.625, "max_line_length": 71, "alphanum_fraction": 0.6868686869}
import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';

/**
 * Scrolls page to top after location change.
 * https://reacttraining.com/react-router/web/guides/scroll-restoration
 */
const ScrollToTop = ({ children }) => {
  const location = useLocation();

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [location]);

  return children;
};

ScrollToTop.propTypes = {
  children: PropTypes.node
};

export default ScrollToTop;
