React Native Navigation,如何在类组件之间传递和使用Props?

问题描述 投票:0回答:1

导出默认类LoginScreen扩展了React.component {

render () {
     return (
         <Button = {()=>this.props.navigation.navigate('Home', {number: 5} />
      )
}

}

HomeScreen类扩​​展了React.Component {render(){返回({this.props}//我想显示传递的数字)}}

reactjs navigation native
1个回答
0
投票

您可以像这样使用本机导航通过props传递。在此示例中,我创建了一个函数,该函数返回一个对象,这就是我喜欢传递道具的方式,因为它使我可以通过道具发送对象而不会使onPress处理程序混乱。

export default class LoginScreen extends React.component {
  navObject = () => {
    let details = {
      name: "Hey",
      description: "This is a test",
      value: 5,
    };
    return details;
  };

  render() {
    return (
      <Button
        onPress={() => {
          this.props.navigation.navigate("Home", this.navObject());
        }}
      />
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.