0

I have part of a React Component that looks like this:

<div onClick={() => handleTriggerParent()}>
    <button type='button' onClick={() => handleTriggerChildren()}>
         Children
    </button>
</div>

I want to ignore handleTriggerParent() method when handleTriggerChildren() method is triggered.

What's the best way to achieve this?

Adasboy
  • 5
  • 3
  • Does this answer your question? [How to call stopPropagation in reactjs?](https://stackoverflow.com/questions/35914680/how-to-call-stoppropagation-in-reactjs) – Janez Kuhar Aug 16 '21 at 10:55

1 Answers1

0

Look into: https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation

Define the button's click handler like so:

onClick={(e) => {
  e.stopPropagation();
  handleTriggerChildren();
}}
Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45