【问题标题】:Retrieve data from screen to screen in react native在本机反应中从屏幕到屏幕检索数据
【发布时间】:2021-04-09 17:23:47
【问题描述】:

我正在将数据“item.email”从屏幕 X 发送到屏幕 HomeParent 如何在 HomeParent 屏幕中检索数据?

  renderItem=(item,index)=>{
    return(
       <View style={styles.listItemContainer}>
          <TouchableOpacity onPress={()=>this.props.navigation.navigate("HomeParent",item.email)}>
            <View style={styles.listItemTitleContainer}>
              <Text>Hello</Text>
            </View>
          </TouchableOpacity>
        </View>
    )
  }

【问题讨论】:

    标签: react-native react-native-flatlist flatlist


    【解决方案1】:

    将其作为对象字段传递

    <TouchableOpacity onPress={()=>this.props.navigation.navigate("HomeParent",{mail:item.email})}>
    

    并像这样使用 getParam,

    const email = this.props.navigation.getParam('mail') 
    

    【讨论】:

    • 我可以在 all 类中使用 getParam 吗?还是必须在componentDidMount函数中写?
    • @user123456 无需在组件didMount func中写入。该参数将作为道具传递给您的组件,因此您的道具可以在类中访问它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多