usetoast callback when toast clears
When using
useToast
and creating a dynamic toast with toast.add
is it possible to have a callback that triggers a function when the dynamically created toast clears?5 Replies
Hi @Neil. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources do not mention any built-in callback or event in the Nuxt UI's useToast composable that triggers a function specifically when a toast is cleared or removed (either individually or via clear()). The documented API for useToast includes methods to add, update, remove, and clear toasts, but there is no reference to a callback or event hook for toast removal or clearing actions. If you need this functionality, you may need to implement a custom solution by watching the toasts array and reacting to its changes manually in your component logic useToast composable.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@355679368078557194> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai Can you provide an example of watching the toasts array and reacting to its changes?
@kapa.ai could you provide an example of watching the toasts array and reacting to its changes?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Certainly! The knowledge sources confirm that useToast exposes a reactive toasts array containing all current toast notifications useToast composable. While there is no built-in callback for when a toast is cleared, you can use Vue's watch function to observe changes to this array and react accordingly.
Here’s an example of how you might watch the toasts array and run a callback when a toast is removed:
This approach lets you react whenever a toast is removed from the array, effectively simulating a "toast cleared" callback useToast composable.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@355679368078557194> Kapa.ai is still learning and improving, please let me know how I did by reacting below.