timolins / react-hot-toast

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

Support multiple <Toaster> elements #158

Open mrmiguu opened 2 years ago

mrmiguu commented 2 years ago

This might be outside of the scope for this project, but the ability to have multiple <Toaster> elements on a page (where toast() calls could have a ToasterID passed in) would be pretty cool and add a lot flexibility.

Example:

toast('This appears as a toast relative to the <div> parent', relativeToasterId)
toast('This appears as a normal toast')

...

return (
  <>
    <div>
      <Toaster id={relativeToasterId} />
    </div>

    <Toaster />
  </>
)
timolins commented 2 years ago

Hi @mrmiguu! Great suggestion - considered this for v2, but decided not to do it atm.

Let's use this issue to see how the demand is. 👍

oscar-at-seatti commented 2 years ago

This would be super helpful.

TrejoCode commented 2 years ago

Please, consider, would be amazing feature

mrmiguu commented 2 years ago

https://github.com/timolins/react-hot-toast/pull/159 ☝️☝️☝️

This PR, if merged, essentially works like this:

toast('hello', { toasterId: 'unique-id-here' })

...

<Toaster toasterId="unique-id-here" />

This way, only that Toaster will be able to receive toasts to-and-from the string "unique-id-here".

rickyzhangca commented 1 year ago

looking forward to having this!

bolerap commented 1 year ago

hi all, how about this

mattellig commented 1 year ago

This would be an extremely valuable feature! Please consider adding.

Mirajjj commented 1 year ago

Yeah. That is what we need right now. For now we will have to support a different functionality with the same behavior.

Benimation commented 1 year ago

My guess is that this doesn't use React Context yet.

If there could be something like a <ToastProvider>, you could use that multiple times and even nest them, where the innermost provider determines which one should be used. That could be really useful if you have one for general app messages, and another one inside of a sidebar or something like that.

I also noticed that it doesn't work out-of-the-box when you have a component library (in a different package) and want to toast things from there to the main app. A context could make that really easy, but for now I just passed the toast() function to our own context and retrieve it from there rather than importing it.

hyung1721 commented 1 year ago

Any updates on this?

Arcanorum commented 1 year ago

pls ser?

eugene-f02 commented 10 months ago

This would be an extremely valuable feature!

sspenst commented 9 months ago

+1, would definitely be helpful. Having to do some workarounds right now to get toasts to work with headless UI dialogs.

codigoisaac commented 9 months ago

Please consider this feature :)

Hristo-Spasov commented 7 months ago

This would be a great feature,hands down

alexgoff commented 7 months ago

would love to have this feature as well

RyanTippsTX commented 7 months ago

+1 I need some toasts to overlay on my video player

AntoninoGargiuloBID commented 6 months ago

Any news? It would be a great feature.

r-josue commented 5 months ago

Any news? It would be a great feature.

emilywilder commented 5 months ago

Just wanted to add my interest in this feature

fccjr24 commented 3 months ago

need this too

georgiosApo commented 3 months ago

Any news on this? Been a while, would be an amazing feature to have 🤌

fellypsantos commented 3 months ago

I think the owner is not quite available to manage the repo, we have many pending pull requests, few months ago I was needing a feature, I sent a pull request and it's still pending, so I've forked the repo, implemented the feature that I was needing, and sent to NPM, temporary solution.