伙计们,如何在 redux 工具包中将对象追加到空数组中?我在我的切片中设置了一个
currentTimeOfServices:[]
,然后我用有效负载调度一个动作
dispatch(userActions.getCurrentTime({ startTime: startTime, name: item }));
在我的 getCurrenTtime 减速器中我不明白如何附加此项目。
getCurrentTime: (state, action) => {
state.currentTimeOfServices = [
...state.currentTimeOfServices,
{ startTime: action.payload.startTime, name: action.payload.name },
];
}
Run Code Online (Sandbox Code Playgroud)
这是错误的,我知道这一点,但我想知道如何向此 currentTimeOfServices 空数组添加/附加对象?