You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
564 B
26 lines
564 B
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); |
|
} |
|
}
|
|
|