Ad

Onclick Function Is Not Working In React Native Application

- 1 answer

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.

Ad

Answer

Try this-

<TouchableOpacity onPress={this.openPopup}> 
    <View> <Text>...</Text> </View> 
</TouchableOpacity>
Ad
source: stackoverflow.com
Ad