React.js broke dispatchEvent

2019-08-02 19:50发布

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条回答
神经病院院长
2楼-- · 2019-08-02 20:38

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.

查看更多
登录 后发表回答