Closed ajmnz closed 3 weeks ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
sonner | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 27, 2024 0:56am |
would love to see this merged
Hey I actually need this. Could @emilkowalski merge it please?
Here's my workaround in case someone faces the same issue. You need to wrap it under a promise and call resolve() reject() accordingly :
const sendNewCodeWrapper = async () =>{
return new Promise((resolve,reject) =>{
toast.promise(API.users.sendNewAccessCode(email), {
loading: t('sendingAccessCode'),
success: (data) => {
setTimeout(() => {
}, 1000);
resolve(data);
return t('accessCodeSent');
},
error: (ex) => {
setIsSendingCode(false);
reject(ex);
return (ex?.response?.data?.localized_error || ex?.message || t('accessCodeSentError'));
},
finally: () => {
}
});
});
}
Issue:
Closes https://github.com/emilkowalski/sonner/issues/339
What has been done:
toast.promise
now returns anunwrap
method. This method returns a new promise that resolves or rejects when the provided promise does. Made sure to do this in a non-breaking way:id
is still returned.unwrap
. (seebasic.spec
for a test on that)Screenshots/Videos:
N/A