простыми словами, вы неправильно используете Promise.all()
, это потому, что структура выглядит примерно так:
Promise.all([p1, p2,...,pn]).then([r1, r2, ..., rn])
но ваш код выглядит примерно так: Promise.all([p1, p2,...,pn].then(r))
так что в основном ваше обещание. Все должно быть изменено на что-то вроде этого:
getUpdatedStatus = () => {
//fetch updated status,
//list of arrays that are updated to state in `cDM`
const schedules = this.state.schedules;
Promise.all(
schedules
.map(schedule =>
axios({
method: "get",
url: schedule.selfUri,
headers: {
Accept: " someValue"
}
})
))
.then(responses => {
//now you have to iterate over the responses
const isIncomplete = responses.some(r => r.data.data[0].status !== "Complete")
if (isIncomplete) {
this.timeout = setTimeout(() => this.getUpdatedStatus(), 20000);
}
console.log(responses);
this.setState(
{
scheduleStatus: isIncomplete?'Pending':'Complete',//improve this piece of code
},
() => {
console.log(this.state.scheduleStatus);
}
);
})
};
здесь у вас есть рабочая песочница с кодом, который вы предоставили в вашей песочнице.