react-hot-toast
react-hot-toast copied to clipboard
Toast Dismiss not working properly for custom toasts
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.
Can you please provide an example, where this issue can be reproduced?
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
Facing the same issue here. Happy to provide an example if it's needed.
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...
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.