Skip to content

Commit

Permalink
Get history of Toast (#266)
Browse files Browse the repository at this point in the history
Co-authored-by: Dharanish V <[email protected]>
  • Loading branch information
dharanish-v and dharanish-v committed May 23, 2024
1 parent 7d28d42 commit d4c5ee7
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -189,15 +190,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 },
);

0 comments on commit d4c5ee7

Please sign in to comment.