I'm new to react native. I wrote the following code to call a function, if a user clicks on a text.
var login = React.createClass({ openPopup: function(){ console.log("function called"); }, render: function(){ return ( <View onClick={this.openPopup}> <Text> Login </Text> </View> ); } });
Is there anything wrong in the above code? If I click the login text, I'm not getting any feedback in the console.
EDIT This question is react native specific. Not a duplicate of any other question in Stack Overflow.
The React onClick event handler enables you to call a function and trigger an action when a user clicks an element, such as a button, in your app. Event names are written in camelCase, so the onclick event is written as onClick in a React app. In addition, React event handlers appear inside curly braces.
React events are written in camelCase syntax: onClick instead of onclick . React event handlers are written inside curly braces: onClick={shoot} instead of onClick="shoot()" .
To set your mind at ease, the onClick event does work with divs in react, so double-check your code syntax.
Try this-
<TouchableOpacity onPress={this.openPopup}> <View> <Text>...</Text> </View> </TouchableOpacity>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With