diff --git a/src/state.ts b/src/state.ts index b925eca..a559af7 100644 --- a/src/state.ts +++ b/src/state.ts @@ -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(); @@ -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( @@ -295,5 +301,5 @@ export const toast = Object.assign( dismiss: ToastState.dismiss, loading: ToastState.loading, }, - { getHistory, getToasts }, + { getHistory, getToasts, clearHistory }, );