dispatchEvent from react js component

Viewed 1740

I try to dispatch an event within a react component but It throw me this error: "Uncaught DOMException: Failed to execute 'dispatchEvent' on 'EventTarget': The event is already being dispatched"

My global event:

var event = new Event('myevent');

window.addEventListener('myevent', () => {
    console.log("test");
})   

And from my react component I want to fire it:

window.dispatchEvent(event);

Any help? Thanks!

0 Answers
Related