fkhadra / react-toastify

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

dismiss() default behaviour when no arguments are passed #1107

Open somkamarius opened 1 month ago

somkamarius commented 1 month ago

Do you want to request a feature or report a bug?

Feature. Nothing critical, just an idea for an api change. Maybe you'll have some feedback on it too.

What is the current behaviour?

toast.dismiss() currently, when no parameters are passed, dismisses all the active toasts.

However, when some more complicated side effects happen, it's possible to accidentally pass a variable with toastId value that is yet undefined (since it could be stored in useRef value, and perhaps with some setTimeout() usage, or some more complicated usages, toast id is not yet saved in the value). After passing undefined value, all toasts will be closed and that could cause some odd behaviours What is the expected behavior? My suggestion for better UX is perhaps change the api, so that toast.dismiss() always requires a toastId? And then either it could be possible to pass the option flag, so that the decision to dismiss all the toasts is explicit, and not just an accident with and undefined value. Or perhaps you could even introduce .dismissAll() as a separate thing.

Just an idea. Perhaps this could save some confusion on debugging for other consumers. Feedback is welcome. Thanks for maintaining this!