React-native onPress does not trigger

Click does not trigger onPress event

clipboard.png

Mar.02,2021

you can take a look at View's document , and you can see that View does not have a callback function called onPress. If you want to add a click event to it, wrap it with TouchableXXX, for example:

<TouchableOpacity  onPress={()=> this.click()}
    <View></View>
</TouchableOpacity>

you want to use TouchableXXX


onPress={() => this.clicks()}

use the arrow function


View there is no onPress event, Text has.

of course, it's best to use those button-related components, such as TouchableOpacity , etc.

Menu