I'm having this error even though everything seems to return an action in my action creator. I have to use a for loop to make a request for every item in my array. It looks like my Promise.all
is not working, maybe?
Any ideas?
index.js
const store = createStore(
allReducers,
compose(
applyMiddleware(thunk),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
);
actions.js
export const searchPeople = (clientAdress, skill, collaborators) => {
const filteredCollabs = collaborators.filter(collab => collab.skills.includes(skill));
let collab;
let origin = "";
let mode = "";
let promises = [];
for (let i = 0; i < filteredCollabs.length; i++) {
collab = filteredCollabs[i];
origin = `${filteredCollabs[i].latitude},${filteredCollabs[i].longitude}`;
mode = `${filteredCollabs[i].mode}`;
let promise = dispatch => axios
.get(`https://maps.googleapis.com/maps/api/distancematrix/json?origins=${origin}&destinations=${clientAdress}®ion=FR&mode=${mode}&key=${config.gmap.key}`)
.then(response => dispatch({
type: "SET_DURATION",
collab,
duration: response.data.rows[0].elements[0].duration.text
}))
.catch(err => dispatch({
type: "ERROR",
err,
}));
promises.push(promise);
}
function everythingIsDone() {
return dispatch => Promise.all(promises)
.then(values => dispatch({
type: "DONE",
values
}))
.catch(err => dispatch({
type: "ERROR",
err
}))
}
everythingIsDone();
}
Thanks a lot in advance!