如何单击使用本机反应的功能呈现的按钮?

How do I click on a button rendered with the function using react native?

[这是我的代码 (https://hizliresim.com/gPmJDO)

这是我的错误 (https://hizliresim.com/dLYAaD)

在不将函数绑定到组件实例的情况下,将它们设为箭头函数

handleClick = () => {
  alert("test");
};

renderGridItem = ({ item }) => (
  <TouchableOpacity onPress={this.handleClick}>
      ...
  </TouchableOpacity>
);

希望对您有所帮助。有疑问欢迎留言。

将处理函数设为箭头函数。

  handleClick = () => {
      alert("Test Alert");
    }

然后调用它

renderGridItem = ({ item }) => (
  <TouchableOpacity onPress={()=>this.handleClick()}>
      ....
      ...
  </TouchableOpacity>
)

如果将处理函数用作箭头函数,则don.t需要绑定。