在另一个屏幕中反应本机使用状态
React Native Use State in Another Screen
所以我的主屏幕上有一个 this.state.comments,它是一个数组。在我的另一个名为 Comments Screen 的屏幕中,我想显示该状态的结果。 Aka id 喜欢使用那个数组我的意思是 this.state.comments 并将其显示在评论屏幕的 FLATLIST 中。那个文件 Comments Screen 只有一个功能,里面有一个平面列表。有帮助吗?
在Home
中使用this.props.navigation.navigate('Comments',{comments: this.state.comments})
如果使用 react-navigation v4,则在 Comments
屏幕中使用 :
const commentsArray = this.props.navigation.getParam('comments')
如果使用 react-navigation v5 使用:
const commentsArray = this.props.route.params.comments;
作为对您对图片评论的回应,如果 Komentar
是添加到您的导航配置中的屏幕:
const Komentar = (props) =>{
const commentsArray = props.navigation.getParam('comments');
return(
// your code here
)}
因为它是一个功能组件,所以您不能使用 this
来访问道具。
所以我的主屏幕上有一个 this.state.comments,它是一个数组。在我的另一个名为 Comments Screen 的屏幕中,我想显示该状态的结果。 Aka id 喜欢使用那个数组我的意思是 this.state.comments 并将其显示在评论屏幕的 FLATLIST 中。那个文件 Comments Screen 只有一个功能,里面有一个平面列表。有帮助吗?
在Home
中使用this.props.navigation.navigate('Comments',{comments: this.state.comments})
如果使用 react-navigation v4,则在 Comments
屏幕中使用 :
const commentsArray = this.props.navigation.getParam('comments')
如果使用 react-navigation v5 使用:
const commentsArray = this.props.route.params.comments;
作为对您对图片评论的回应,如果 Komentar
是添加到您的导航配置中的屏幕:
const Komentar = (props) =>{
const commentsArray = props.navigation.getParam('comments');
return(
// your code here
)}
因为它是一个功能组件,所以您不能使用 this
来访问道具。