React.js broke dispatchEvent

六月ゝ 毕业季﹏ 提交于 2020-01-05 05:49:09

问题


for example:

I add event handler in react:

<div onClick={someHandler}/>

Then I dispatch event:

let clickEvt = new MouseEvent('click', {
    'bubbles': false,
    'cancelable': true
});

elm.dispatchEvent(clickEvt);

But nothing happens. I hear you can use elm.click() to trigger the react event. I'm wondering if that is the proper way to do it in react? Also what is the difference between click() and dispatchEvent()? Because I kinda want to stick to dispatchEvent().


回答1:


All

I figured it out. bubbles must be set to true for react to receive the event, which is why click() method works, because it automatically bubbles.



来源:https://stackoverflow.com/questions/43098550/react-js-broke-dispatchevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!