timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.55k stars 313 forks source link

Async callbacks for `success` and `error` in toast.promise #303

Open Specy opened 11 months ago

Specy commented 11 months ago

Sometimes to show an error or success dialog we need to fetch additional data, for example, when the api i want to fetch data from returns an error code and i need to fetch the text of the error code before showing it. example:

toast.promise(somePromise, {
    loading: "Saving data:...", 
    success: "Data saved!",
    error: async (e) => `There was an error: ${await getErrorMessage(e)}`
})
MilosMosovsky commented 7 months ago

+1