存储数据时出错,{}-Redux持续存在

时间:2018-07-25 22:28:06

标签: reactjs react-native redux redux-persist

所以我能够成功地将商店链接到我的主App.js,但是现在我收到有关存储数据的错误消息。我试图清除以查看是否可以执行任何操作,但在无法清除存储在存储{}中的数据时遇到了类似的错误。

更新: 该问题与const storage和redux-persist-sensitive-storage库有关。但是,仍然不知道如何使用该库保存数据。

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 ({
    profile: profileReducer,
    auth: authReducer,
    photoSlider,
    trip: tripReducer,
    moment: momentReducer
})

我的减速器之一的示例:

import {
  SET_TRIP,
  CREATE_TRIP
} from '../actions';

const initialState = {
  trip: []
}

const tripReducer = (state = initialState, action) => {
  switch(action.type) {
    case SET_TRIP:
      return {
        ...state,
        trip: action.trip
      };
    case CREATE_TRIP:
      return {
        ...state,
        trip: action.payload
      }

    default:
      return state;
  }
}

export default tripReducer

1 个答案:

答案 0 :(得分:0)

运行react-native link react-native-sensitive-info后,我遇到了同样的问题。

通过在我的pod install目录中运行ios并重建项目来解决该问题