Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
Expand Down Expand Up @@ -294,6 +307,7 @@ export const toast = Object.assign(
promise: ToastState.promise,
dismiss: ToastState.dismiss,
loading: ToastState.loading,
clearHistory: ToastState.clearHistory,
},
{ getHistory, getToasts },
);