diff --git a/src/state.ts b/src/state.ts index b925eca..c5b7c2c 100644 --- a/src/state.ts +++ b/src/state.ts @@ -89,15 +89,28 @@ class Observer { if (id) { this.dismissedToasts.add(id); requestAnimationFrame(() => this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }))); + // Clean up the toast from the internal array after the exit animation completes + setTimeout(() => { + this.toasts = this.toasts.filter((toast) => toast.id !== id); + }, 400); } else { this.toasts.forEach((toast) => { this.subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true })); }); + // Clean up all toasts from the internal array after the exit animation completes + setTimeout(() => { + this.toasts = []; + }, 400); } return id; }; + clearHistory = () => { + this.toasts = []; + this.dismissedToasts.clear(); + }; + message = (message: titleT | React.ReactNode, data?: ExternalToast) => { return this.create({ ...data, message }); }; @@ -294,6 +307,7 @@ export const toast = Object.assign( promise: ToastState.promise, dismiss: ToastState.dismiss, loading: ToastState.loading, + clearHistory: ToastState.clearHistory, }, { getHistory, getToasts }, );