我的问题是我有2个reducer,1个返回一个“ user”对象,另一个返回一个数字,它实际上是“ user”对象的一个属性(user.entries)。
当我尝试组合这两个reducer时,我希望我的第二reducer直接更新User对象的属性,但是我不知道该怎么做。
我说的代码是这样的:
const userReducer = (state = {}, action) => {
switch (action.type) {
case 'USER_LOADED':
return action.payload; // an "user" object
default:
return state;
}
};
const entriesReducer = (state = null, action) => {
switch (action.type) {
case 'ADD_ENTRIES':
return action.payload; // a number
default:
return state;
}
};
export default combineReducers({
user: userReducer,
user.entries: entriesReducer // i know this is not correct...
});
答案 0 :(得分:0)
结构错误,您应该仅将combinedReducers用于兄弟姐妹。此处的条目是User的子属性。最好这样一起写。
Array [Object { name: "Netflix", user: 1 }, Object { name: "Comcast", user: 2 }, Object { name: "Verizon", user: 4 }]