【发布时间】: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