Reputation: 115
I have this line in my React Native app :
<Image onPress={alert('Image')} source={require('./assets/home.png')} />
I want it to show an alert after clicking on the image, the problem is the alert appears after the login without even clicking on the Image or anything.
Upvotes: 1
Views: 82
Reputation: 696
As it stands, and as you've found, your function will be called immediately. To get the interaction you want you need to use the following
<Image onPress={() => alert('Image')} source={require('./assets/home.png')} />
Upvotes: 4