错误类型:存储区没有有效的reducer。请确保传递给combineReducers的参数是其值为reducer的对象。
我正在尝试添加应用商店,但我的应用出现故障。我不知道错误来自何处。有人能指出我的错误以及如何修复吗?
贮藏
import { configureStore } from '@reduxjs/toolkit';
import rootReducers from './reducers';
const store = configureStore({
reducer: rootReducers,
});
export default store;
还原剂
x一个一个一个一个x一个一个二个x
1条答案
按热度按时间thigvfpy1#
我在
handleCart
reducer函数代码中只看到几个明显的问题,可能是引发异常的原因。handleCart
reducer函数在默认情况下似乎缺少返回状态。REMOVEITEM
情况还错误地假定已定义exist
,并访问可能未定义的对象的qty
属性。请记住,当在数组中找不到匹配元素时,Array.prototype.find
将返回undefined
。确保默认导出
handleCart
,以便可以将其导入以创建根缩减器。你正在使用redux-toolkit,为什么不创建状态切片?这里有一个类似的使用
createSlice
的实现。这允许你使用可变更新来编写reducer函数,而不需要浅拷贝状态的所有部分。