我正在获取数据,然后将它们保存在移动设备上的 sqlite 文件中。当这个屏幕被调用时,获取代码开始被componentDidMount()函数调用。当提取结束时,这会setState()调用componenDidUpdate()函数(将数据保存在 sqlite then 中setState= 'isLoadingDataProgramadas: false'),所以我希望应用程序'ActProgramadas'使用 React-Navigation V3 转换到屏幕。下面的解决方案有效,但给我一个警告:
警告:在现有状态期间无法更新(例如在“渲染”内)。渲染方法应该是 props 和 state 的纯函数。
我该如何解决?
componentDidMount() {
this.doFetch();
}
componentDidUpdate(){
this.openBD();
this.insertSQLITE();
}
componentWillUnmount() {
this.closeDatabase();
}
render() {
if(this.state.isLoadingDataProgramadas)
return (
<View style={stylesLoading.container}>
<View>
<ActivityIndicator size="large" color="lightblue"/>
</View>
<View>
<Text style={stylesLoading.texto}>
Descargando datos...
</Text>
</View>
</View>
);
else
return(
<View>
{this.props.navigation.navigate('ActProgramadas')}
</View>
);
}