React.js打破了dispatchEvent

问题描述:

例如:

我在事件中添加事件处理程序:

I add event handler in react:

<div onClick={someHandler}/>

然后我调度事件:

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

elm.dispatchEvent(clickEvt);

但是什么也没发生.我听说您可以使用elm.click()来触发react事件.我想知道这是否是正确的反应方式? click()dispatchEvent()有什么区别?因为我有点想坚持dispatchEvent().

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().

全部

我知道了. bubbles必须设置为true才能作出反应以接收事件,这就是click()方法起作用的原因,因为它会自动冒泡.

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.