Created
February 15, 2019 17:09
-
-
Save joeljuca/e0f355551b12f9274a1db094fe08fd91 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
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