Closed kash0296 closed 1 year ago
I ran into something similar. The solution is in the documentation. As usual I just glossed over the docs and missed this part.
https://react-hot-toast.com/docs/toast
Prevent duplicate toasts To prevent duplicates of the same kind, you can provide a unique permanent id.
toast.success('Copied to clipboard!', {
id: 'clipboard',
});
@bbeus88 thanks man! i did skim the docs and i missed it too. I ended up googling it and because i found nothing there i figured i'd ask here. thanks again!
Here's an example scenario:
I call an API twice, to update two different sets of data on the backend. I just call the function to make that API request twice, with the respective data passed on as a payload. So in this case, when the API call has been completed, i display a toast to inform the user that their action has been successfully completed, or that it has failed. Because the same function is called twice, there are two toasts on the screen, both which have the same toast message. How can i prevent the display of duplicate toasts in this scenario? Is there something available within the library for me to handle this?
Thanks in advance. Please let me know if any sample code needs to be shared for better understanding. My assumption is that its a fairly straightforward scenario, but I can provide an example if needed.
Thanks in advance!