React native 定期备份redux
我正在世博会管理的RN应用程序中使用redux persist,并使用localStorageReact native 定期备份redux,react-native,redux,local-storage,redux-persist,React Native,Redux,Local Storage,Redux Persist,我正在世博会管理的RN应用程序中使用redux persist,并使用localStorage import storage from 'redux-persist/lib/storage' 根据下面的配置,这会将状态存储在本地存储中,并具有密钥root const persistConfig = { key: 'root', storage, } 我希望定期使用时间戳将此状态保存到远程服务器,并且仅当本地状态过时或不存在时才使用该保存的状态 使用案例是在服务器上备份设备数据,当用户
import storage from 'redux-persist/lib/storage'
根据下面的配置,这会将状态存储在本地存储中,并具有密钥root
const persistConfig = {
key: 'root',
storage,
}
我希望定期使用时间戳将此状态保存到远程服务器,并且仅当本地状态过时或不存在时才使用该保存的状态
使用案例是在服务器上备份设备数据,当用户更改设备或从其他设备登录时,他们可以从远程服务器恢复应用程序状态
注意:我不想要像Firebase或Realm这样的实时存储。所有数据都是从本地设备使用的,但只是定期保存到远程设备,备份的数据可以稍微落后于本地副本。(想象一下WhatsApp对Google Drive的备份,这是零星的、周期性的)
我正在考虑使用Expo AppLoading组件获取和保存本地存储,例如在App.js中
render() {
if (!this.state.isLoadingComplete) {
return (
<AppLoading
startAsync={this._syncFromRemoteAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
);
} else {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<View style={styles.container}>
<AppNavigator />
</View>
</PersistGate>
</Provider>
);
}
}
render(){
如果(!this.state.isLoadingComplete){
返回(
);
}否则{
返回(
);
}
}
现在在\u syncFromRemoteAsync
函数中,我计划对我的服务器进行API调用,检查时间戳并与根键控本地存储进行比较,如果远程数据不存在或过时,则将本地存储上载到远程服务器;如果本地存储过时或不存在,则下载并覆盖本地存储
两个非常相关的问题