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
8 changes: 7 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ class Observer {
getActiveToasts = () => {
return this.toasts.filter((toast) => !this.dismissedToasts.has(toast.id));
};

clearHistory = () => {
this.toasts = this.getActiveToasts();
this.dismissedToasts.clear();
};
}

export const ToastState = new Observer();
Expand Down Expand Up @@ -280,6 +285,7 @@ const basicToast = toastFunction;

const getHistory = () => ToastState.toasts;
const getToasts = () => ToastState.getActiveToasts();
const clearHistory = () => ToastState.clearHistory();

// We use `Object.assign` to maintain the correct types as we would lose them otherwise
export const toast = Object.assign(
Expand All @@ -295,5 +301,5 @@ export const toast = Object.assign(
dismiss: ToastState.dismiss,
loading: ToastState.loading,
},
{ getHistory, getToasts },
{ getHistory, getToasts, clearHistory },
);