此操作将引发以下错误:
setTimerState(state, { payload }: PayloadAction<{ timer: StepTimer, timerState: CookingTimerState }>) {
const { timer, timerState } = payload
const timerInStore = state.stepTimers
.find(t => t.timerId === timer.timerId)!
timerInStore.state = timerState
}
错误:不变失败:在调度中的以下路径中检测到状态突变:CookingSession.stepTimers.0.state。看一下处理操作的减速器{“ type”:“ session / setTimerState”,“ payload”:{“ timer”:{“ label”:“ Dance”,“ durationSec”:600,“ stepIndex” :0,“ timerId”:0:“状态”:2},“ timerState”:2}}
我认为Redux工具包允许您进行这种状态更改。
是因为我的StepTimer
是类对象而不是POJO?
答案 0 :(得分:0)
正确。只有原始值,对象和数组才被认为是可序列化的,而类实例则不是。
根据Redux样式指南,you shouldn't be putting class instances in your state。