Redux-persist |删除persistor.pruge时,状态未定义

时间:2018-01-24 13:14:12

标签: reactjs react-native redux redux-saga redux-persist

我有一个应用程序,它从服务器加载数据并将其保存在状态中。我需要存储一些这些状态来减少服务器的负载。但当我评论我的configureStore应用程序中的persistor.purge()不再启动时!

configureStore.js

import { createStore, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import hardSet from 'redux-persist/lib/stateReconciler/hardSet';
import logger from 'redux-logger';
import createSagaMiddleware from 'redux-saga';

import reducers from '../reducers';
import rootSaga from './sagas';

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

if (process.env.NODE_ENV === 'development') {
  middleware.push(logger);
}

const persistConfig = {
  key: 'rootApp',
  storage,
  stateReconciler: hardSet,
};


const persistedReducer = persistReducer(persistConfig, reducers);

export default () => {
  const store = createStore(persistedReducer, applyMiddleware(...middleware));
  sagaMiddleware.run(rootSaga);
  const persistor = persistStore(store);
  // persistor.purge();
  return { store, persistor };
};

index.js

import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/es/integration/react';
import configureStore from './config/configureStore';

const { store, persistor } = configureStore();
const onBeforeLift = () => {
  // take some action before the gate lifts
};

const App = () => (
  <Provider store={store}>
    <PersistGate loading={null} onBeforeLift={onBeforeLift} persistor={persistor}>
      <MainStack />
    </PersistGate>
  </Provider>
);

export default App;

错误:

screenshot from 2018-01-24 16-36-36

0 个答案:

没有答案