我曾尝试将redux-persist与redux和redux-saga集成以获取对pwa的离线支持。问题可能是由于redux持续的Incorrent集成所致。
这是我的州状态离线对象。
有没有更简单的方法可以在redux中保持状态。
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter } from 'react-router-dom';
import { createStore, applyMiddleware, compose } from "redux";
import { persistStore, persistCombineReducers } from 'redux-persist';
import storage from 'redux-persist/es/storage';
import { Provider } from "react-redux";
import createSagaMiddleware from "redux-saga";
import { PersistGate } from 'redux-persist/integration/react'
import './index.css';
import App from './App';
// ServiceWorker
import registerServiceWorker from './registerServiceWorker';
// Saga
import {
watchApp,
watchLogin,
} from "./store/sagas";
// Reducers
import loginReducer from './store/reducers/login';
import appReducer from './store/reducers/app';
const composeEnhancers =
process.env.NODE_ENV === "development"
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: null || compose;
/* Redux-Persist */
const rootPersistReducer = persistCombineReducers({
key: 'root',
storage,
},{
app: appReducer,
login: loginReducer,
});
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
rootPersistReducer,
composeEnhancers(applyMiddleware(sagaMiddleware)),
);
/* Redux-Persist + Store */
export const persistor = persistStore(store);
sagaMiddleware.run(watchApp);
sagaMiddleware.run(watchLogin);
const app = (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<HashRouter>
<App />
</HashRouter>
</PersistGate>
</Provider>
)
ReactDOM.render(app, document.getElementById('root'));
registerServiceWorker();