【问题标题】:Redux store (AsyncStorage engine) freezes iPhone when calling store.dispatchRedux 存储(AsyncStorage 引擎)在调用 store.dispatch 时冻结 iPhone
【发布时间】:2021-04-21 12:48:33
【问题描述】:

对于我们的 ReactNative 应用,我们通过使用内部存储来消除加载时间。 最初,来自 redux 存储的数据可以立即渲染,同时进行 api 调用以更新数据。 api调用后最新的数据存储在store.dispatch中。

在 Android 和模拟器上一切正常,但在 iPhone X 上,应用程序在调用 store.dispatch 时冻结。删除调度“解决”了问题。

可能是什么问题?我们应该尝试其他存储引擎吗?

编辑: 我根据我们的编码创建了一个基本的 redux 应用程序:https://snack.expo.io/@adriaandebolle/react-native---redux-store。使用 Expo 客户端,这在 iPhone 上运行良好。因此无法重现该问题...

我们的 store.js 文件:

import {createStore, compose, applyMiddleware} from 'redux';

import thunk from 'redux-thunk';

import {persistCombineReducers, persistStore} from 'redux-persist';
import AsyncStorage from '@react-native-community/async-storage';

import {encryptTransform} from 'redux-persist-transform-encrypt';

const encryptor = encryptTransform({
  secretKey: '******',
  onError: function (error) {
    // Handle the error.
    console.log(error);
  },
});

const config = {
  key: 'primary',
  storage: AsyncStorage,
  transforms: [encryptor],
};

import {reducer as servicesReducer} from 'app/services/reducer';

const appReducer = persistCombineReducers(config, {
  services: servicesReducer,
});

const enhancer = compose(applyMiddleware(thunk));

const store = createStore(appReducer, enhancer);

const persistor = persistStore(store);

export {store, persistor};

依赖包.json

{  
  "dependencies": {
    "npm": "^6.14.8",
    "react": "16.13.1",
    "react-native": "0.63.4",
    "react-navigation": "^4.0.10",
    "react-navigation-stack": "^1.9.4",
    "react-redux": "^7.2.2",
    "redux": "^4.0.5",
    "redux-persist": "^6.0.0",
    "redux-persist-transform-encrypt": "^3.0.1",
    "redux-thunk": "^2.3.0",
    "remote-redux-devtools": "^0.5.16",
  },
}

【问题讨论】:

    标签: reactjs react-native redux react-redux asyncstorage


    【解决方案1】:

    这不是操作系统问题,而是我存储的数据量。 AsyncStorage 有一个大小限制,某些帐户超过了该限制。一些警告可能很有趣,或者是找出哪个减速器导致达到限制的方法。

    使用arr.splice() 可以大大减少存储数组的大小。一切正常。但是很高兴知道我们在“安全区”中的情况。

    【讨论】:

      猜你喜欢
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 2017-09-16
      • 1970-01-01
      • 2019-06-19
      相关资源
      最近更新 更多