无法读取未定义的 属性 'subscribe' - Redux Persist

Cannot read property 'subscribe' of undefined- Redux Persist

我收到的更具体的错误是:警告:道具类型失败:道具 storeProvider 中被标记为必需,但其值为 undefined

store.js

const initialState = {};

const storage = createSensitiveStorage({
  keychainService: "myKeychain",
  sharedPreferencesName: "mySharedPrefs"
});

const config = {
  key: "root",
  storage,
};

const middleware = [thunk];

const reducer = persistCombineReducers(config, rootReducer);

export default () => {
  let store = createStore(
    reducer,
    initialState,
    compose(applyMiddleware(...middleware))
  );
  let persistor = persistStore(store);

  return { store, persistor }
}

index.js 减速机:

export default combineReducers({
    profile: profileReducer,
    auth: authReducer,
    photoSlider,
    trip: tripReducer,
    moment: momentReducer
})

App.js:

import {store, persistor} from './src/store';

<Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <Layout />
        </PersistGate>
      </Provider>

如有任何帮助,我们将不胜感激。

store.js 中,您不导出 storepersistor,您导出 returns 具有 storepersistor。因此,您在 App.js 中的 import 语句实际上导入了两个不存在的 命名导入

您可以这样获取您的实例:

import factory from './src/store';

const {store, persistor} = factory();

<Provider store={store}>
  <PersistGate loading={null} persistor={persistor}>
     <Layout />
  </PersistGate>
</Provider>