Prevent onClick event by clicking on a child div

前端 未结 2 677
醉酒成梦
醉酒成梦 2021-01-14 17:27

I\'m trying to create a modal in React JS

I have one outter div which is the whole body and I have I inner div. I want to apply the function to close the modal if it

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-14 18:06

    Attach a function to the inner div which stops propagation.

       function stopPropagation(e) {
          e.stopPropagation();
       }
    

    In your case

    Does this help you: ReactJS SyntheticEvent stopPropagation() only works with React events?

提交回复
热议问题