I am having problems of receiving the data from a api fetch, I am guessing data might received after the console.log()?
How can I fix this?
fetch("https://www.cheapshark.com/api/1.0/games?title=batman")
.then(response => response.json())
.then(data => {
console.log(data[0])
})
This code return a object data straight away
fetch("https://www.cheapshark.com/api/1.0/games?title=batman")
.then(response => response.json())
.then(data => {
this.setState({api: data[0] ,loading:false})
})
console.log(this.state.api)
However, I'll need to save the fetched data into the state, but when I call it after saving it, it returns a empty object, that influences me to print the data to UI.
Help....