サーバーからデータをロードして状態に保存するアプリがあります。サーバーからの負荷を軽減するために、これらの状態のいくつかを保存する必要があります。しかし、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;
エラー: