react-toastify icon indicating copy to clipboard operation
react-toastify copied to clipboard

Feature request: Be able to update all existing toasts without knowing their ids

Open xsjcTony opened this issue 3 years ago • 2 comments

Do you want to request a feature or report a bug? Feature


What is the current behavior? When I want to update a toast, I have to know its id

toats.update(toastId, { /* options */ })

What is the expected behavior? I want to update all current toasts that are showing on the screen, without knowing all their ids and iterating through.

toast.update(null, { /* options */ }) // or another signature like `toast.update(options)`

It will work just like toast.dismiss() which closes all existing toasts without passing all their ids in.

xsjcTony avatar Aug 22 '22 08:08 xsjcTony

Hey @xsjcTony, not sure this is something that I would put in core. You can already implement such functionality.

const ids = []

// everytime you call toast, you would store the id
ids.push(toast("something"))

function updateAll(opts){
 ids.forEach(id => toast.update(id, opts))
}

It could potentially be an addon

fkhadra avatar Aug 24 '22 06:08 fkhadra

@fkhadra Yeah such functionality can be implemented but since toast can be triggered anywhere in the component tree, I may need an extra global state for storing ids which is an extra cost, that's why I think such a feature would be great.

xsjcTony avatar Aug 24 '22 06:08 xsjcTony