redux 在多个时持续崩溃

redux persist crash when multiple

我在 React js 应用程序中使用 redux-persist。 我有 2 个减速器,叫做:auth、streams。 当我将它们与 persistReducer

一起定义时
import { combineReducers } from 'redux';
import storage from 'redux-persist/lib/storage' 
import { persistReducer } from 'redux-persist'
import { combineReducers } from 'redux';
import storage from 'redux-persist/lib/storage' 
import { persistReducer } from 'redux-persist'

import auth  from './auth.reducer';
import stream  from './stream.reducer';

const rootPersistConfig = {
  key: 'root',
  storage: storage,
  whitelist: ['auth','stream'],
}
const authPersistConfig = {
    key: 'auth',
    storage: storage,
  };
const streamsPersistConfig = {
  key: 'stream',
  storage: storage,
  };





const rootReducer = combineReducers({
  auth:persistReducer(authPersistConfig,auth),
  stream:persistReducer(streamsPersistConfig,stream),
});

export default persistReducer(rootPersistConfig, rootReducer)\

它崩溃并抛出错误

但是当我只定义一个 persistReducer 时(不管是哪个)

import { combineReducers } from 'redux';
import storage from 'redux-persist/lib/storage' 
import { persistReducer } from 'redux-persist'

import auth  from './auth.reducer';
import stream  from './stream.reducer';

const rootPersistConfig = {
  key: 'root',
  storage: storage,
  whitelist: ['auth','stream'],
}
const authPersistConfig = {
    key: 'auth',
    storage: storage,
  };




const rootReducer = combineReducers({
  auth:persistReducer(authPersistConfig,auth),
  stream:stream
});

export default persistReducer(rootPersistConfig, rootReducer)

它工作正常,没有抛出任何错误。

我的解决方案类似于以下代码段

// store.js

import { createStore, combineReducers } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import auth from './auth'
import stream from './stream'

const persistConfig = {
  key: 'root',
  storage,
}

const rootReducer = combineReducers({
  auth,
  stream,
})

const persistedReducer = persistReducer(persistConfig, rootReducer)

export default () => {
  const store = createStore(persistedReducer)
  const persistor = persistStore(store)

  return { store, persistor }
}