3
In the 'componentDidMount' function of REACT I get the json of a link in question, but in the 'render' I cannot pass these objects because the object is in a '.then' in the first function. How can I accomplish that?
componentDidMount(){
let URL = 'http://algumaUrl'
fetch(URL)
.then(function(response) {
let data = response.json()
return data;
})
.then((json) => {
console.log(json)
// this.setState({data : json});
this.setState({data : json});
grafico = json;
})
.catch(function(ex) {
console.log('parsing failed', ex)
})
}
render () {
console.log('grafico ', grafico);
}
My chart receives the JSON that I acquired through GET, but to show on screen it will appear null, because the same is in the then.
Thank you very much.
– Henrique Hermes