我正在使用 redux、redux-persist 和中间件 redux-thunk 来获取 Json API。我的问题是当 wifi 关闭时我不能再使用它了。存储不能很好地离线使用。
Here is my codes.
Store.js
-------------
import { createStore, applyMiddleware, compose } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/es/storage';
import thunk from 'redux-thunk';
import rootReducer from './RootReducers';
const middleware = [thunk];
const persistConfig = {
key: 'root',
storage
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancers = composeEnhancers(
applyMiddleware(...middleware),
);
export default () => {
const store = createStore(persistedReducer, enhancers)
const persistor = persistStore(store);
return { store, persistor: persistor };
};