1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
你有在deleteItem行動(dòng){ type, payload }。相反,您可以在 reducer return 語(yǔ)句中擁有{ type, id }或使用。payload
我會(huì)做以下事情 - 所以你通過(guò)id而action不是傳遞payload:
export const deleteItem = id => {
console.log("actions");
return {
type: DELETE_ITEM,
id
};
};
或者以后用途的最佳選擇 - 繼續(xù)payload添加id為屬性:
// action
export const deleteItem = id => {
console.log("actions");
return {
type: DELETE_ITEM,
payload: { id }
};
};
// reducer
case DELETE_ITEM:
// here destructuring the property from payload
const { id } = action.payload;
return {
...state,
items: state.items.filter(item => item.id !== id)
};
我希望這有幫助!
添加回答
舉報(bào)