timolins / react-hot-toast

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

How to update an existing toast? #231

Closed OnkelTem closed 1 year ago

OnkelTem commented 1 year ago

Is there a way to update an existing toast?

For example, if an error happens more than once, it shouldn't be repeated; instead, the previous one should be updated with a counter. It's similar to what browsers do when printing messages in the console.

I don't find this information in the docs or here in the issues.

timolins commented 1 year ago

Yep, there you go: https://react-hot-toast.com/docs/toast#update-an-existing-toast

toast("123", {
  id: "count"
})

toast("456", {
  id: "count"
})

// or

const toastId = toast("123")

toast("456", {
  id:  toastId
})
OnkelTem commented 1 year ago

Thank you very much @timolins ! Meanwhile, I've also discovered the purpose of the useToaster() hook which can be used to create any render, including filtering or updating one.