Answer the question
In order to leave comments, you need to log in
How to array promises in redux?
export function homePageProfileAction(list, name) {
return (dispatch) => {
dispatch(homePageProfileFetchId(list, name));
let promise = list.map(v => {
console.log(getUserHome(v));
return getUserHome(v).then(id => {
dispatch(homePageProfileFetchSuccess(id, v));
});
});
// Promise.all([promise])
// .then((res) => {
// console.log(res);
// dispatch(homePageProfileFetchSuccess(res, "top"));
// })
// .catch(err => {console.log(err); });
};
}
Answer the question
In order to leave comments, you need to log in
export function homePageProfileAction(list, name) {
return (dispatch) => {
dispatch(homePageProfileFetchId(list, name));
const promises = list.map(v => getUserHome(v));
Promise.all(promises)
.then((res) => {
dispatch(homePageProfileFetchSuccess(res, "top"));
})
.catch(err => {console.log(err); });
};
}
Promise.all will return an array of responses from all executed requests. See what you return in then of each request and how you process it afterwards.
export function homePageProfileAction(list, name) {
return (dispatch) => {
dispatch(homePageProfileFetchId(list, name));
let promise = list.map(v => {
return getUserHome(v);
});
Promise.all(promise)
.then((ids) => {
console.log(ids);
//dispatch(homePageProfileFetchSuccess(res, "top"));
})
.catch(err => {console.log(err); });
};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question