Skip to content

Instantly share code, notes, and snippets.

@r1ckhenry
Created January 29, 2020 22:21
Show Gist options
  • Save r1ckhenry/d9ba27f13ef78c42e708cd862878fdaf to your computer and use it in GitHub Desktop.
Save r1ckhenry/d9ba27f13ef78c42e708cd862878fdaf to your computer and use it in GitHub Desktop.
import React from "react";
import axios from "axios";
class Fetcher extends React.Component {
state = {
fetching: false,
data: []
};
componentDidMount = () => {
const { url } = this.props;
this.setState({ fetching: true });
axios.get(url).then(response => {
this.setState({ data: response.data, fetching: false });
});
};
render = () => {
const { props } = this;
return React.cloneElement(props.children, this.state);
};
}
export default Fetcher;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment