我试图在我的减速器中修改“ duration”属性的值。 当我console.log个人的“ collab”时,一切都很好。但是,然后,我无法正确更新我的newState。
你有什么主意吗?
export function reducer(state = initialState, action) {
let newState = [...state];
switch (action.type) {
case "SEARCH_PEOPLE":
newState = initialState;
let results;
axios
.get(`https://maps.googleapis.com/maps/api/distancematrix/json?origins=${origins}&destinations=${destination}®ion=FR&key=${config.gmap.key}`)
.then(res => {
results = res.data.rows;
newState = newState.map((collab, i) => {
return console.log("collab : ", {
...collab,
duration: results[i].elements[0].duration.text
})
}
)
})
return newState;
default:
break;
}
return newState;
}
谢谢!