import React from 'react'; export class Fetch extends React.Component { state = { loading: true, error: false, done: false, data: [], }; componentDidMount() { fetch(this.props.url) .then(res => { if (!res.ok) { throw new Error(res.status); } return res.arrayBuffer(); }) .then(data => this.setState({ loading: false, done: true, data })) .catch(error => this.setState({ loading: false, done: false, error })); } render() { return this.props.children(this.state); } }