react-hot-toast icon indicating copy to clipboard operation
react-hot-toast copied to clipboard

Toast Dismiss not working properly for custom toasts

Open M-Subhan1 opened this issue 2 years ago • 5 comments

Toast Dismiss is not working properly for custom toasts. The toast does not go away even after the toast.dismiss function is called with the id of the toast. I am using the one from the Tailwind CSS example on the official website.

M-Subhan1 avatar Apr 20 '22 17:04 M-Subhan1

Can you please provide an example, where this issue can be reproduced?

timolins avatar Apr 21 '22 18:04 timolins

I don't have an example handy, but I am having the same issue - using Tailiwnd based custom toast, toast.dismiss() is not working. However, toast.close() is

jonathanfox-socialive avatar Apr 27 '22 01:04 jonathanfox-socialive

Facing the same issue here. Happy to provide an example if it's needed.

stasundr avatar May 11 '22 06:05 stasundr

I'm finding that toast.dismiss() closes all custom toasts, and I needed to write toast.dismiss(t.id); given t is the instance. The API was a bit misleading here, I would expect instead there to be a "toast.dismissAll" that requires no props, and toast.dismiss to require an instance id...

jameswilliamknight avatar Jul 12 '23 23:07 jameswilliamknight

In a separate component called Alert.jsx develop your custom component and add the useEffect hook to it like this:

useEffect(() => {
    setTimeout(() => {
      toast.dismiss(t.id);
    }, 2000);
  }, []);

The amount of time can be made dynamic by passing it as a parameter.

fervillalbag avatar Jul 19 '23 00:07 fervillalbag