React Native onPress being called automatically

前端 未结 5 1399
悲&欢浪女
悲&欢浪女 2020-12-12 20:20

I am having trouble with react-native onPress Feature. The onPress should only work when it is actually been triggered by a touch event (i suppose) , that is when i press th

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 21:06

    try to change

    onPress={this.handleRoute('x')} // in this case handleRoute function is called as soon as render happen

    to

    onPress={() => this.handleRoute.bind('x')} //in this case handleRoute doesn't called as soon as render happen

提交回复
热议问题