3

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!

Car Lautaro
  • 301
  • 1
  • 2
  • 8

0 Answers0