onParentClick = () => {
console.log('Parent is triggered');
}
onChildClick = (event) => {
event.stopPropagation();
console.log('Child is triggered');
}
<TouchableWithoutFeedback onPress={()=> this.onParentClick()}>
<View>
<Text>How to prevent parent click event</Text>
<TouchableOpacity onPress={(event)=> this.onChildClick(event)}>
<Text> Click Me </Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
<!-- edit description:- there was this end curly brace missing in above,
however the snippet will not run because the language js will not
support it and language html will not be able to format it correctly or run it.
(need to run the snippet on the react native environment like code-pen) -->
Expected: On click of "Click Me", onChildClick() must be called
Issue: On click of "Click Me", onParentClick() is called.
How to prevent parents click event on click of "Click Me"?Result which I get on click of parent is "Parent is triggered" and it works perfect.
But on click on child the result I get is "Parent is triggered".
I guess onChildClick() is not being triggered.