React · Junior · Question 59 of 75

How do you stop a click inside a card from also triggering the card's onClick?

<div onClick={openCard}>
  <button onClick={(e) => { e.stopPropagation(); like(); }}>Like</button>
</div>

Explanation

React events bubble like DOM events (except onScroll). Returning false doesn't stop anything in React; use stopPropagation or preventDefault explicitly.

Further reading

Problem with a question

React · Junior · question 59

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz