Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Created February 15, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeljuca/e0f355551b12f9274a1db094fe08fd91 to your computer and use it in GitHub Desktop.
Save joeljuca/e0f355551b12f9274a1db094fe08fd91 to your computer and use it in GitHub Desktop.
class DataFetcher extends React.Component {
componentWillMount() {
this.setState(this.props.initialState)
this.props.fetcher().then(newState => this.setState(newState))
}
render() {
<TablePage {...this.state} />
}
}
<DataFetcher
component={TablePage}
initialState={{
title: "Produtos"
}}
fetcher={() => {
return axios.get('http://api.swapi.co/films')
.then(res => res.data)
.then(films => {
const newState = {
columns: [
"title",
"episode_id"
],
data: films,
}
return newState
})
}} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment