【发布时间】:2021-04-05 01:41:02
【问题描述】:
在我的 redux react 应用程序中更新数组的旧值时遇到问题。我已经成功更新了新的选定对象true。我想将其他对象设置为false,因为我已将另一个对象设置为true。
const initialState = {
annualPlans: [],
};
const planReducer = (state = initialState, action) => {
switch (action.type) {
case planConstants.UPGRADE_PLAN_SUCCESS:
return {
...state,
annualPlans: state.annualPlans.map((todo) =>
todo.value === action.data.plan_id
? // transform the one with a matching id
{ ...todo, current: true }
: // otherwise return original todo
todo
),
};
default:
return state;
}
};
【问题讨论】:
标签: reactjs redux ecmascript-6 react-redux