Skip to content

An opinionated toast component for React.

Trigger animation on remove

emilkowalski3f6deb066f34
diff --git a/src/index.tsx b/src/index.tsx
index f5b5526..b8910f0 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -195,6 +195,12 @@ const Toast = (props: ToastProps) => {
}
}, [setHeights, toast.id]);
+ React.useEffect(() => {
+ if (toast.delete) {
+ deleteToast();
+ }
+ }, [toast.delete]);
+
const promiseTitle = React.useMemo(() => {
switch (promiseStatus) {
case 'loading':
@@ -207,7 +213,7 @@ const Toast = (props: ToastProps) => {
return null;
}
}, [toast.promiseData, promiseStatus]);
-
+ console.log(toast.delete);
return (
<li
aria-live={toast.important ? 'assertive' : 'polite'}
@@ -408,9 +414,7 @@ const Toaster = (props: ToasterProps) => {
React.useEffect(() => {
return ToastState.subscribe((toast) => {
if ((toast as ToastToDismiss).dismiss) {
- console.log(toast.id);
-
- removeToast(toast);
+ setToasts((toasts) => toasts.map((t) => (t.id === (toast as ToastToDismiss).id ? { ...t, delete: true } : t)));
return;
}
diff --git a/src/types.ts b/src/types.ts
index 9775edd..a109b80 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -19,6 +19,7 @@ export interface ToastT {
invert?: boolean;
description?: string;
duration?: number;
+ delete?: boolean;
important?: boolean;
action?: {
label: string;