{"size": 782, "ext": "js", "max_stars_repo_path": "src/DataLoader.js", "max_stars_repo_name": "JosuaKrause/react_vis_tutorial", "max_stars_repo_stars_event_min_datetime": "2017-09-20T00:04:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-08T08:37:31.000Z", "max_issues_repo_path": "src/DataLoader.js", "max_issues_repo_name": "JosuaKrause/react_vis_tutorial", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/DataLoader.js", "max_forks_repo_name": "JosuaKrause/react_vis_tutorial", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.619047619, "max_line_length": 77, "alphanum_fraction": 0.5396419437}
import React, { PureComponent } from 'react';
import { doFetch } from './util.js';

class DataLoader extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      values: [],
    };
    this.unmounted = false;
  }

  componentWillUnmount() {
    this.unmounted = true;
  }

  componentDidMount() {
    doFetch("/data.json", (data) => {
      if(this.unmounted) return;
      this.setState({
        values: data["values"],
      });
    });
  }

  render() {
    const { children } = this.props;
    const { values } = this.state;
    return (
      <div>
        {
          React.Children.map(children, (child) => React.cloneElement(child, {
            values
          }))
        }
      </div>
    );
  }
} // DataLoader

export default DataLoader
