I'm working in React and trying to fill a ImageGrid with data from a API. There is no problem with getting the data but somehow I cant set my state with the responseData
I can show the data while I get the response from the API but I can't set my state...
componentWillMount()
{
this.state = {
content: ''
};
this.loadContent();
}
loadContent()
{
ApiService.getTweets(topic,numberOfElements,offset).then((responseData) => {
console.log("Data is here",responseData); //<---------- HERE
this.setState({
content: responseData
});
})
console.log("Data is not here",this.state.content); //<---------- HERE
}
Here I get the data:
class ApiService {
static getTweets() {
return fetch("https://MyURL", {
method: 'get'
})
.then((resp) => resp.json())
.then(function(data) {
return data;
}).catch(function(error) {
console.log(error);// Error :(
});
}
}
export default ApiService;