Skip to content

Commit

Permalink
toast.promise accept function
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Aug 27, 2021
1 parent f154fdd commit a38fde4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ interface ToastPromiseParams {
}

function handlePromise<T>(
promise: Promise<T>,
promise: Promise<T> | (() => Promise<T>),
{ pending, error, success }: ToastPromiseParams,
options?: ToastOptions
) {
Expand Down Expand Up @@ -161,11 +161,12 @@ function handlePromise<T>(
});
return result;
};
promise
.then(result => resolver('success', success, result))
.catch(err => resolver('error', error, err));
const p = isFn(promise) ? promise() : promise;
p.then(result => resolver('success', success, result)).catch(err =>
resolver('error', error, err)
);

return promise;
return p;
}

toast.promise = handlePromise;
Expand Down

0 comments on commit a38fde4

Please sign in to comment.