React prevent event bubbling in nested components on click

前端 未结 8 1536
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 02:41

Here\'s a basic component. Both the

    and
  • have onClick functions. I want only the onClick on the
  • to fir
8条回答
  •  生来不讨喜
    2020-11-27 03:12

    The new way to do this is a lot more simple and will save you some time! Just pass the event into the original click handler and call preventDefault();.

    clickHandler(e){
        e.preventDefault();
        //Your functionality here
    }
    

提交回复
热议问题