【发布时间】:2021-08-17 08:33:04
【问题描述】:
您好,我有一个 reducer,其中包含一个 array 和 objects。这些objects 有一些属性。当我在redux 中使用useDispatch Hook dispatch 和action 时,我想动态添加更多属性。我怎样才能实现这个目标
//reducer数据
users: [
{
id: 1,
first_name: "JACKILINE",
status: "online",
},
{
id: 2,
first_name: "BRONNNZE",
status: "offline",
},
];
我想动态添加这两个属性mesg: "how are you",lastSeenDate: "30/11/19", 如何更新reducer中的状态
//我想要在 dispatch 一个 action 后像这样的 reducer
users: [
{
id: 1,
first_name: "JACKILINE",
status: "online",
mesg: "how are you",
lastSeenDate: "30/11/19",
},
{
id: 2,
first_name: "BRONNNZE",
status: "offline",
mesg: "how are you",
lastSeenDate: "30/11/19",
},
],
`
//我的行动
export const setLastMessage = (payload) => ({
type: actionTypes.SET_LAST_MESSAGE,
payload: {
id: payload.id,
lastSeenDate: payload.date,
mesg:payload.message
},
});
【问题讨论】:
-
你不使用
useSelector钩子调度,你会使用useDispatch
标签: reactjs redux react-redux react-hooks