Redux Persist,无法在Android设备上补水

时间:2018-10-31 06:43:48

标签: react-native react-redux expo

我有一个基于React Native&Expo的应用程序。我的应用程序和redux持久保存可以正常工作,直到我终止了一个应用程序进程。重新启动redux后,持久性无法恢复(没有错误),并且存储在存储中的所有数据也会丢失。

有人知道我做错了什么吗? 或者也许我没有设置任何东西?

这是我的商店配置。

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

import appReducer from '../scenes/App/app.reducer';
//...other reducers
import actionReducer from '../lib/managers/action.reducer';

const reducer = combineReducers({
  app: appReducer,
  //...other reducers
  action: actionReducer,
});

const persistConfig = {
  key: 'root',
  storage,
  blacklist: ['log', 'action'],
  stateReconciler: autoMergeLevel2,
};

const persistedReducer = persistReducer(persistConfig, reducer);
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

function configureStore() {
  return createStore(persistedReducer, composeEnhancers());
}

1 个答案:

答案 0 :(得分:0)

您如何引导您的应用程序?您正在使用 react-native-navigation 吗?还是其他rooters方法?

此配置似乎并不正确,但问题可能出在您如何包装根目录(也许您也应该共享该位)

请参见redux-persist documentation,以了解如何使用PersistGate来包装根目录:

import { PersistGate } from 'redux-persist/integration/react'

// ... normal setup, create store and persistor, import components etc.

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