I am using promise.all inside componentdidmount to get response.data from two apis.
constructor(){
super();
this.state = {
data: [],
p1: [],
p2: []
};
}
async componentDidMount() {
const [res1, res2] = await Promise.all([
axios.get(api1),
axios.get(api2)
]);
this.setState({
p1: res1.data,
p2: res2.data
});
console.log("this.state.p1" ,this.state.p1)
console.log("this.state.p2" ,this.state.p2)
}
Sometimes both this.state.p1 and this.state.p2 return correct data but sometimes when I refresh my page this.state.p1 returns data of this.state.p2 and this.state.p2 becomes empty.