fkhadra / react-toastify

React notification made easy 🚀 !
https://fkhadra.github.io/react-toastify/introduction
MIT License
12.33k stars 676 forks source link

How to distinguish autoClose from manual dismiss #1000

Open demigor opened 9 months ago

demigor commented 9 months ago

I'm struggling to remove toasts from Notification Center, that were manually closed (with close button click).

However, in onClose there is no way to distinguish wether the toast was closed automatically (via timeout) or by user action (close button click).

Tried with custom button, but the button does not receive any toast related properties, so there is no way to dismiss related toast from notification center in button's onClick event.

Any help would be appreciated. Thank you

ouassim2 commented 9 months ago

If you listen for the onChange event on toast it returns a ToastItem payload. Inside of it you can check the toast status property . When you click inside the toast, close the toast with x and on toast autoClose they ALL return status : removed

in my case there is no way for me to reproduce the onClick event which was working only when you click inside the toast and not on the x button.

In your case its the onClose that has the same status.

here is the link to try it out yourself : https://fkhadra.github.io/react-toastify/listen-for-changes