I am using React's componentDidMount to carry out ajax calls operations and based on the returned results setting data to react state variable.
Now I need to use the react state variable values by calling several different methods as I want to do the operations on page load but somehow it's not working. I have also tried timeout but it's not consistent.
Anyone have any idea, what's going wrong?
Here is some sample code:
componentDidMount() {
Helper.GetReview1Data().then(data => {
this.setState({
review1data: data
})
})
Helper.GetReview2Data().then(data=> {
this.setState({
review2data: data
})
})
this.get1Data()
this.get2Data()
}
get1Data = () => {
console.log(this.state.review1data.map(i=>i.name))
console.log(this.state.review2data.map(i=>i.name))
}
get2Data = () => {
console.log(this.state.review2data.map(i=>i.name))
}