react-native onPress binding with an argument

前端 未结 6 2110
予麋鹿
予麋鹿 2020-12-24 04:42

The desired behaviour is to pass an argument (text) to the onClick handler to console.log it but it seems that I\'m doing something wrong with the syntax.

If I leave

6条回答
  •  轮回少年
    2020-12-24 05:20

    You can solve it with fat arrows too:

    export default class Nav extends Component {
    
      handlePress = (text) => {
        console.log(text);
      }
    
      render() {
        return (
          
            ####################
            Intro Screen
            Number: {this.props.numbers}
             this.handlePress('weeeeee')}>
              Go to Foo
          
        
        );
      }
    }
    

提交回复
热议问题