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()
.
All
I figured it out.
bubbles
must be set totrue
for react to receive the event, which is whyclick()
method works, because it automatically bubbles.