【发布时间】:2019-12-31 06:33:38
【问题描述】:
我的reducer如下:
export const favorites = (state = {
favorites: [],
countFavorite: [],
}, action) => {
switch (action.type) {
case ActionTypes.ADD_FAVORITE:
return { ...state, favorites: action.payload };
case ActionTypes.COUNT_FAVORITE:
return { ...state, countFavorite: [...state.countFavorite, action.payload] };
default:
return state;
}
};
当前我得到以下与旧状态和新状态:
我希望新对象用数组中的相同键覆盖现有对象,非常感谢任何帮助
【问题讨论】:
标签: javascript react-native redux redux-reducers