我正在尝试将我正在构建的应用程序切换为使用 Redux Toolkit,并且在我从 createStore 切换到 configureStore 时注意到出现此错误:
A non-serializable value was detected in the state, in the path: `varietals.red.0`. Value:, Varietal {
"color": "red",
"id": "2ada6486-b0b5-520e-b6ac-b91da6f1b901",
"isCommon": true,
"isSelected": false,
"varietal": "bordeaux blend",
},
Take a look at the reducer(s) handling this action type: TOGGLE_VARIETAL.
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)
Run Code Online (Sandbox Code Playgroud)
在四处探索之后,我发现问题似乎出在我的自定义模型上。例如,品种数组是从品种模型创建的:
class Varietal {
constructor(id, color, varietal, isSelected, isCommon) {
this.id = id;
this.color = color;
this.varietal = varietal;
this.isSelected = isSelected;
this.isCommon = isCommon;
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它映射一个字符串数组来创建我的 Varietal 数组,该数组进入我的状态:
// my utility …Run Code Online (Sandbox Code Playgroud)