I am doing the .get()
request in Jquery and updated the state as well.
My question is:
Why am I not able to see the data in console.log(this.state.storage)
in componentWillMount()
as well as componentDidMount()
but I do get the output in render()
?
Also I will need to do operations on fetched data, in which lifecycle I should do it?
constructor() {
super();
this.state = {
storage: []
}
}
componentWillMount() {
$.get('data.csv', (data) => this.setState({
storage: data
}));
console.log(this.state.storage); //No Output
}
componentDidMount() {
console.log(this.state.storage); //No Output
}
render() {
return (
<div >{this.state.storage}</div> //Do get the Output
);