From 8f0ea2c829b9b17a747c1f20d9021152d1c4049c Mon Sep 17 00:00:00 2001 From: Dharanish V <30527938+Dharanish3499@users.noreply.github.com> Date: Sun, 24 Dec 2023 19:05:08 +0530 Subject: [PATCH] getHistory function added in state --- src/state.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/state.ts b/src/state.ts index 89e8df1..fb6f306 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,5 +1,6 @@ +import type { ExternalToast, PromiseData, PromiseT, ToastT, ToastToDismiss, ToastTypes } from './types'; + import React from 'react'; -import type { ExternalToast, ToastT, PromiseData, PromiseT, ToastToDismiss, ToastTypes } from './types'; let toastsCounter = 1; @@ -181,15 +182,21 @@ const toastFunction = (message: string | React.ReactNode, data?: ExternalToast) const basicToast = toastFunction; +const getHistory = () => ToastState.toasts; + // We use `Object.assign` to maintain the correct types as we would lose them otherwise -export const toast = Object.assign(basicToast, { - success: ToastState.success, - info: ToastState.info, - warning: ToastState.warning, - error: ToastState.error, - custom: ToastState.custom, - message: ToastState.message, - promise: ToastState.promise, - dismiss: ToastState.dismiss, - loading: ToastState.loading, -}); +export const toast = Object.assign( + basicToast, + { + success: ToastState.success, + info: ToastState.info, + warning: ToastState.warning, + error: ToastState.error, + custom: ToastState.custom, + message: ToastState.message, + promise: ToastState.promise, + dismiss: ToastState.dismiss, + loading: ToastState.loading, + }, + { getHistory }, +);