[英]How do I click on a button rendered with the function using react native?
[Here is My Code ( https://hizliresim.com/gPmJDO ) [这是我的代码( https://hizliresim.com/gPmJDO )
Here is My Error ( https://hizliresim.com/dLYAaD )这是我的错误( https://hizliresim.com/dLYAaD )
Without binding your function to a component instance, make them as arrow functions无需将您的函数绑定到组件实例,将它们设为箭头函数
handleClick = () => {
alert("test");
};
renderGridItem = ({ item }) => (
<TouchableOpacity onPress={this.handleClick}>
...
</TouchableOpacity>
);
Hope this helps you.希望这对你有帮助。 Feel free for doubts.如有疑问,请放心。
Make a handler function as arrow function.将处理函数作为箭头函数。
handleClick = () => {
alert("Test Alert");
}
An then call it然后调用它
renderGridItem = ({ item }) => (
<TouchableOpacity onPress={()=>this.handleClick()}>
....
...
</TouchableOpacity>
)
You don.t need to bind if you use handler function as an arrow function.如果使用处理函数作为箭头函数,则不需要绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.