【发布时间】:2019-05-13 14:32:08
【问题描述】:
我正在获取数据,然后将它们保存在移动设备上的 sqlite 文件中。当这个屏幕被调用时,获取代码开始被componentDidMount() 函数调用。当提取结束时,setState() 会调用componenDidUpdate() 函数(将数据保存在 sqlite 然后setState= 'isLoadingDataProgramadas: false')所以我希望应用程序使用 React-Navigation V3 转换到'ActProgramadas' 屏幕。下面的解决方案有效,但给我一个警告:
警告:在现有状态期间无法更新(例如在 '使成为')。渲染方法应该是 props 的纯函数和 状态。
我该如何解决这个问题?
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>
);
}
【问题讨论】:
标签: android reactjs react-native navigation react-navigation