reactjs - 在调度中检测到状态突变:即使使用工具包
问题描述
此操作引发以下错误:
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" 的 reducer :0,"timerId":0,"state":2},"timerState":2}}
我认为 Redux 工具包允许您进行这种状态更改。是因为我StepTimer
的 s 是类对象而不是 POJO 吗?
解决方案
正确的。只有原始值、对象和数组被认为是可序列化的,而类实例不是。
根据 Redux Style Guide,您不应该将类实例放在您的 state中。
推荐阅读
- java - 将 Java HashSet 转换为 PHP
- python - Django Admin Sortable 2不保存订单
- detection - Google Cloud Vision API 上是否有任何选项可以从扫描的图像中检测并返回表格(带有标题的行和列)?
- spring-integration - Spring集成dsl outboundGateway使用表达式设置查询参数
- python - 无法从远程机器连接到 Cassandra 服务器
- amazon-web-services - aws s3 sync 是否有最小尺寸才能工作?
- apache-spark - 调度从 HDFS 导出到 S3 的输出
- 2d - Armadillo 2D FFTW 实数到复数 DFT Hermetian 对称性
- docker - 通过 docker 容器上传文件
- json - kotlinx JSON.stringify 忽略空值