【发布时间】:2016-12-24 22:04:05
【问题描述】:
我在减速器中有一个对象数组,如下所示:
[
{id:1, name:Mark, email:mark@email.com},
{id:2, name:Paul, email:paul@gmail.com},
{id:3,name:sally, email:sally@email.com}
]
下面是我的减速机。到目前为止,我可以通过以下方式向currentPeople reducer 添加一个新对象:
const INITIAL_STATE = { currentPeople:[]};
export default function(state = INITIAL_STATE, action) {
switch (action.type) {
case ADD_PERSON:
return {...state, currentPeople: [ ...state.currentPeople, action.payload]};
}
return state;
}
但这就是我卡住的地方。我可以使用 lodash 通过减速器更新一个人吗? 如果我发送如下所示的操作负载:
{id:1, name:Eric, email:Eric@email.com}
我可以用新字段替换 id 为 1 的对象吗?
【问题讨论】:
标签: object reactjs redux store lodash