question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onClose event trigger 2 times.

See original GitHub issue

onCloese event trigger 2 times Following the code, I am getting closed alert two times once before showing the message & another one after closing the message.

        toast.success('Successfully registered!', {
          onClose: () => alert('closed')
        });

Video

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fkhadracommented, Jun 1, 2022

@lfernandez55 I feel your pain. Having a piece of code not acting the same way in dev and prod is a nightmare.

The larger concern however is why this isn’t being seen as a bug worth fixing.

It’s not that it’s not worth fixing. React does not provide any API so far to address this behavior. Having to fix a framework behavior in a library is not always easy, especially in this case where the library code doesn’t do too much. You would encounter the same issue in your App if you use useEffect for mount and unmount. In that case, it’s visible because it calls a callback.

As a maintainer, this is super frustrating. I really hope that the react team provides an alternative to this in a near future. All I can do now is propose an alternative 😞. If there was an easy fix, I would implement it right away, rest assured.

From the react documentation:

If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument.
1reaction
dyabolcommented, Apr 21, 2022

onCloese event trigger 2 times Following the code, I am getting closed alert two times once before showing the message & another one after closing the message.

        toast.success('Successfully registered!', {
          onClose: () => alert('closed')
        });

Video

I think is related with this https://github.com/reactwg/react-18/discussions/19 Try disable React.StrictMode, it’s not solution, but unit someone fix it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the onClick event triggered twice? - Stack Overflow
It is calling twice because button is inside a span and span has onclick="alert('Boem')" , hence when you trigger click on button then...
Read more >
Help with JavaScript event triggered twice :( : r/FreeCodeCamp
When you close the modal, it doesn't get rid of the next and prev buttons, it just hides them, meaning those event listeners...
Read more >
How To Handle DOM and Window Events with React
In this tutorial, you'll learn how to handle events in React. ... This will add the event listener every time you trigger the...
Read more >
onunload Event - W3Schools
Note: The onunload event is also triggered when a user reloads the page (and the onload event). Browser Support. Event. onunload, Yes, Yes,...
Read more >
.unload() | jQuery API Documentation
A function to execute each time the event is triggered. ... 2. 3. $( window ).unload(function() {. return "Handler for .unload() called.";. }); ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found