emilkowalski / sonner

An opinionated toast component for React.
https://sonner.emilkowal.ski
MIT License
7.69k stars 237 forks source link

Option to not produce new toast in promise success and error methods #420

Closed Gobot1234 closed 1 month ago

Gobot1234 commented 1 month ago

Describe the feature / bug šŸ“:

Currently I have code that updates the current toast using the flow: action -> promise -> result. The code looks like this

          const t = toast(
            PopUp("out", async () => {
              toast.promise(PostSignOut(userProps), {
                id: t,
                error: (e) => {
                  toast.error(
                    <>
                      {`Failed to sign out user ${uCardNumber}`}
                      <br />
                      {(e as any).toString()}
                    </>,
                    { id: t },
                  );
                },
                success: () => {
                  queryClient.invalidateQueries({ queryKey: ["locationStatus", "locationList", { activeLocation }] });
                  toast.success(`Successfully signed out ${uCardNumber}`, { id: t });
                },
              });
            }),
          );

I'd like to not produce empty toasts at the end of this without resorting to hacks. In my mind returning undefined/void/false should be enough for a case like this. LMK if you have any other opinion :)

Gobot1234 commented 1 month ago

Sorry didn't realise this was the behaviour already