【问题标题】:error storing data, {}- Redux Persist存储数据时出错,{}- Redux Persist
【发布时间】:2019-01-02 20:12:42
【问题描述】:

所以我能够成功地将我的商店链接到我的主 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

【问题讨论】:

    标签: reactjs react-native redux redux-persist


    【解决方案1】:

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

    通过从我的ios 目录运行pod install 并重建项目解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2019-09-20
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多