2
上面的问题说明了一切。我正在使用HomeScreen的StackNavigation。 HomesScreen具有组件位置和状态位置,其中位置存储到AsyncStorage。In React Nativigation如何更新状态goBack
使用GoBack的()功能,我想导航到主屏幕(导航部分已经完成),并更新状态位置。我想更新位置状态以在HomeScreen中显示位置。
主屏幕渲染:
<View>
<Text style=>{(this.state.location) ? (this.state.location) : ('Select Current Location')}</Text>
</View>
位置组件
await AsyncStorage.getItem('location').then((location) => {
this.setState({location: location, persistedLocation: location})
});
await AsyncStorage.getItem('region').then((region) => {
this.setState({region: region, persistedRegion: region})
});
流量:
什么更新“goBack()”状态到HomeScreen?
有没有办法以更好的方式做到这一点?
'this.setState({location:location,persistedLocation:location})'是一个异步,这可能是你的主屏幕没有获得更新值的原因 –
为什么?即使我没有等待和异步也检查。你能告诉我是否可以在从位置设置器屏幕执行goBack()之后添加回调吗? – subhajit