Skip to content

An opinionated toast component for React.

Pass props correctly

emilkowalski66d73f907f49
diff --git a/src/index.tsx b/src/index.tsx
index a61a8ca..58bca4e 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -4,7 +4,7 @@ import React from 'react';
import './styles.css';
import { getAsset, Loader } from './assets';
-import { HeightT, Position, ToastT, ToastToDismiss } from './types';
+import { HeightT, Position, PromiseData, ToastT, ToastToDismiss } from './types';
import { ToastState, toast } from './state';
// Visible toasts amount
@@ -204,15 +204,15 @@ const Toast = (props: ToastProps) => {
const promiseTitle = React.useMemo(() => {
switch (promiseStatus) {
case 'loading':
- return toast.promiseData.loading;
+ return (toast as PromiseData).loading;
case 'success':
- return toast.promiseData.success;
+ return (toast as PromiseData).success;
case 'error':
- return toast.promiseData.error;
+ return (toast as PromiseData).error;
default:
return null;
}
- }, [toast.promiseData, promiseStatus]);
+ }, [promiseStatus]);
return (
<li
diff --git a/src/state.ts b/src/state.ts
index 4c187b0..780f633 100644
--- a/src/state.ts
+++ b/src/state.ts
@@ -49,7 +49,7 @@ class Observer {
promise = (promise: PromiseT, data?: PromiseData) => {
const id = toastsCounter++;
- this.publish({ promiseData: data, promise, id });
+ this.publish({ ...data, promise, id });
return id;
};
diff --git a/src/types.ts b/src/types.ts
index e29d80e..635614c 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -2,14 +2,14 @@ import React from 'react';
export type ToastTypes = 'normal' | 'action' | 'success' | 'error' | 'loading';
-export type PromiseData = {
- loading: string;
+export type PromiseT = Promise<any> | (() => Promise<any>);
+
+export type PromiseData = ExternalToast & {
+ loading: string | React.ReactNode;
success: string | React.ReactNode;
error: string | React.ReactNode;
};
-export type PromiseT = Promise<any> | (() => Promise<any>);
-
export interface ToastT {
id: number;
title?: string | React.ReactNode;
@@ -30,7 +30,6 @@ export interface ToastT {
onClick?: () => void;
};
promise?: PromiseT;
- promiseData?: PromiseData;
style?: React.CSSProperties;
className?: string;
descriptionClassName?: string;