Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 在另一个屏幕中反应本机使用状态_React Native_Expo_React Native Flatlist - Fatal编程技术网

React native 在另一个屏幕中反应本机使用状态

React native 在另一个屏幕中反应本机使用状态,react-native,expo,react-native-flatlist,React Native,Expo,React Native Flatlist,所以我的主屏幕上有一个this.state.comments,这是一个数组。在我的另一个名为评论屏幕的屏幕中,我想显示该状态的结果。我想使用这个数组,我的意思是this.state.comments,并在comments屏幕的平面列表中显示它。“文件注释”屏幕只有一个函数,其中有一个平面列表。有什么帮助吗?在主页中使用这个.props.navigation.navigate('Comments',{Comments:this.state.Comments}) 如果使用react navigati

所以我的主屏幕上有一个this.state.comments,这是一个数组。在我的另一个名为评论屏幕的屏幕中,我想显示该状态的结果。我想使用这个数组,我的意思是this.state.comments,并在comments屏幕的平面列表中显示它。“文件注释”屏幕只有一个函数,其中有一个平面列表。有什么帮助吗?

主页中
使用
这个.props.navigation.navigate('Comments',{Comments:this.state.Comments})

如果使用react navigation v4,则在
注释
屏幕中使用:

const commentsArray=this.props.navigation.getParam('comments')

如果使用react navigation v5,请使用:


const commentsArray=this.props.route.params.comments

作为对您的评论的图片回应,如果
Komentar
是添加在导航配置中的屏幕,您可以:

constkomentar=(道具)=>{
const commentsArray=props.navigation.getParam('comments');
返回(
//你的代码在这里
)}

因为它是一个功能组件,您不能使用
访问道具。

只需使用react导航将该数组从主屏幕传递到评论屏幕。首先,屏幕使用react导航?或者只是父-子组件,我们需要更多信息尝试如果您不使用react导航,或者希望避免在屏幕之间传递数据,您还可以使用AsyncStorage在第一个屏幕上设置comments对象,并在另一个屏幕上检索它-这正是我需要的。但是,我在执行ur const commentsArray=this.props.navigation.getParam('Comments')行时遇到此错误。评估this.props.navigation.navigate您使用什么版本的react navigation?并检查是否有打字错误。我使用v4。idk我需要在这个小评论屏幕中包含什么才能使用这一行const commentsArray=this.props.navigation.getParam('comments')我想我需要导入一些东西才能让它正常工作?请看这张图片谢谢!这加上你写下的东西帮我搞定了诀窍谢谢你!!