如何使用persistStore()持久存储?我遇到错误“商店没有有效的减速器”

时间:2019-05-28 12:07:45

标签: reactjs react-native redux redux-persist

我相信我正确地在persistCombineReducers()内部传递了“ reducer”以及“ config”来创建一个持久存储。但是我遇到一个错误,说-'商店没有有效的减速器'

import { createStore } from 'redux'
import { persistStore, persistCombineReducers } from 'redux-persist'
import storage from 'redux-persist/es/storage'

...


const reducer = (state=initialState, action) => {
  switch(action.type){
    ...
  }
}

...


export const store =
  createStore(persistCombineReducers(config, reducer), initialState)

export const persistor = persistStore(store)

...

我希望这家商店能够长期存在。而是会引发错误-“商店没有有效的减速器”

1 个答案:

答案 0 :(得分:1)

使用persistReducer代替persistCombineReducers

PersistReducer用于只有1个reducer并以一个函数为参数,而persistCombineReducers以一个对象为参数(一个包含减速器列表的对象)的情况。