Created
January 29, 2020 22:21
-
-
Save r1ckhenry/d9ba27f13ef78c42e708cd862878fdaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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