How can I call method from onPress on Alert function [React-Native]

前端 未结 1 901
渐次进展
渐次进展 2021-02-18 19:51

How can I call method from onPress on Alert function [React-Native]

1条回答
  •  既然无缘
    2021-02-18 20:08

    First issue, the Button component has a title prop instead of having as a child. Second issue is that you have a bunch of syntax errors and are not calling functions (or binding) correctly. If you fix that, then it should work fine; for example:

    alert = (msg) => {
      console.log(msg)
    }
    
    onDeleteBTN = () => {
      this.alert(' OnDelete')
    }
    
    render() {
      return (
        
          

    Note:

    • I don't know what your alert() function is supposed to do, so I made a dummy one that logs to console.
    • There are other ways of doing this like calling onDeleteBTN() or binding.

    0 讨论(0)
提交回复
热议问题