2

I recently started using react-toastify and everything worked fine until I noticed this odd behavior.

Here is my code: this.adderrorNotification('Error: Please try again!')

adderrorNotification(message){ 
 toast.error(message, { 
   onClose: () => console.log('called when I close') 
 }); 
}

enter image description here

Up on toast onClose I see the log message 4 times. and up on manual close click the toast re-appears 4 times.

Why is this happening ? Any help Thanks

Aravind Reddy
  • 353
  • 4
  • 18
  • 1
    Can you post your index file where toast is initialized? – Alex May 28 '21 at 03:32
  • 1
    Your comment just made me realize that I have initialized my toast in all my components which was causing the issue. (Sidebar, Navbar, Main component, Footer) which is making that render 4 times. Thanks a lot – Aravind Reddy May 28 '21 at 03:39
  • No problem! Glad I could help. Remember to mark your question as answered! – Alex May 28 '21 at 20:20

1 Answers1

1

Answering my own question:

Cause: Initialized the toast in all my components which was causing the issue. (Sidebar, Navbar, Main component, Footer) which is making that render 4 times.

Solution: Removing the toast initialization in all components and initialized it in the index.js solved my issue.

Aravind Reddy
  • 353
  • 4
  • 18