react-native async function returns promise but not my json data?
Another approach similar to the original code of the questioner:
async componentDidMount() {
let data = await this.getData();
console.log(data);
this.setState({
dataSource:this.state.dataSource.cloneWithRows(data),
})
}
Since getData()
is a promise, you should be able to obtain the data in a then
block as follows:
componentDidMount() {
this.getData()
.then((data) => {
this.setState({
dataSource:this.state.dataSource.cloneWithRows(data),
})
});
}