fkhadra / react-toastify

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

Conditionally prevent toast on error with toast.promise? #1023

Closed shueja closed 7 months ago

shueja commented 7 months ago

I'm using toast.promise() with success and error messages. For most errors, I have the toast show the error message. However, if the error message contains "User_Requested_Stop", I want no toast to show. Is there something I can return from the error callback in toast.promise() to not actually show a toast?

makibat commented 7 months ago

Have you tried this approach

       error: {
          render({ toastProps, data }) {
            if (data.message === "User_Requested_Stop") {
              toastProps.style = { visibility: 'hidden' };
            }

            return data.message;
          }
        }
shueja commented 7 months ago

I’d missed the toastProps option. That should work well for this, thanks!