问题描述报错信息:Storedoesnothaveavalidreducer.MakesuretheargumentpassedtocombineReducersisanobjectwhosevaluesarereducers.问题出现的环境背景及自己尝试过哪些方法我将不同功能的reducer放到不同的文件夹下,然后使用redux-persist进行数据持久化处理,web项目会经常刷新么,所以想让store中的数据不丢失,然而合并reducer应用combineReducers方法是报错,不知道为什么相关代码//请把代码文本粘贴到下方(请勿用图片代替代码)reducerimport*asPagesfrom'./action-types';letdefaultValue={user_name:"",user_id:""}exportdefaultfunctionUserInfo(state=defaultValue,action={}){switch(action.type){casePages.SAVEUSERINFO:return{...state,...{user_name:action.data.data.username,user_id:action.data.data.id}};default:returnstate;}}合并位置import{combineReducers,}from'redux';importUserInfofrom'./Pages/reducers';importSaveInfofrom'./Layout/reducers';constrootReducer=combineReducers({UserInfo,SaveInfo});exportdefaultrootReducer;入口文件import{Provider}from'react-redux';import{createStore,applyMiddleware}from'redux';//这个Reducers就是我合并的reducerimportReducersfrom'@/Reducers';importthunkfrom'redux-thunk';import{persistStore,persistCombineReducers}from'redux-persist';import{PersistGate}from'redux-persist/es/integration/react';importstoragefrom'redux-persist/es/storage'constconfig={key:'root',storage,};functionconfigureStore(){console.log(Reducers)letreducer=persistCombineReducers(config,Reducers);letstore=createStore(reducer,applyMiddleware(thunk));letpersistor=persistStore(store);return{persistor,store}}constrender=Component=>{const{persistor,store}=configureStore();ReactDOM.render(//绑定redux、热加载,document.getElementById('app'),)}你期待的结果是什么?实际看到的错误信息又是什么?期待无论怎么刷新浏览器,刷新之前的store中的数据能保存到刷新之后来
2 回答
德玛西亚99
TA贡献1770条经验 获得超3个赞
persistCombineReducers这个方法不知道是我用的不对还是被官方废弃了,看文档使用persistReducer方法来合并config和reducer即可完成实现import{persistStore,persistReducer}from'redux-persist';constpersistedReducer=persistReducer(persistConfig,Reducers)functionconfigureStore(){letstore=createStore(persistedReducer,applyMiddleware(thunk));letpersistor=persistStore(store);return{persistor,store}}constrender=Component=>{const{persistor,store}=configureStore();ReactDOM.render(//绑定redux、热加载 ,document.getElementById('app'),)}哪位大神如果有具体的问题原因也烦请告知一下,感激不尽
添加回答
举报
0/150
提交
取消