Helper Function with argument called before component mount in React Native

前端 未结 1 924
长情又很酷
长情又很酷 2021-01-24 01:15

I\'m testing that my express server is running in React Native by calling a simple helper function in my component.

This is the helper function:

//Helpe         


        
相关标签:
1条回答
  • 2021-01-24 02:13

    That's because you invoked it immediately in the template.

    Replace

    <Button title="Test Fetch" onPress={this.testFetch('Here I am')} />

    To

    <Button title="Test Fetch" onPress={() => this.testFetch('Here I am')} />

    Read more about it here https://reactjs.org/docs/faq-functions.html

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