react-hot-toast icon indicating copy to clipboard operation
react-hot-toast copied to clipboard

Support multiple <Toaster> elements

Open mrmiguu opened this issue 2 years ago • 17 comments

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 />
  </>
)

mrmiguu avatar Mar 05 '22 23:03 mrmiguu

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. 👍

timolins avatar Mar 06 '22 13:03 timolins

This would be super helpful.

oscar-at-seatti avatar Mar 07 '22 10:03 oscar-at-seatti

Please, consider, would be amazing feature

TrejoCode avatar Mar 10 '22 22:03 TrejoCode

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".

mrmiguu avatar Mar 11 '22 08:03 mrmiguu

looking forward to having this!

rickyzhangca avatar Nov 08 '22 04:11 rickyzhangca

hi all, how about this

bolerap avatar Nov 10 '22 11:11 bolerap

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

mattellig avatar May 03 '23 20:05 mattellig

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

Mirajjj avatar May 09 '23 18:05 Mirajjj

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.

Benimation avatar May 26 '23 14:05 Benimation

Any updates on this?

hyung1721 avatar Jun 19 '23 08:06 hyung1721

pls ser?

Arcanorum avatar Jul 29 '23 13:07 Arcanorum

This would be an extremely valuable feature!

eugene-f02 avatar Oct 14 '23 07:10 eugene-f02

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

sspenst avatar Nov 04 '23 21:11 sspenst

Please consider this feature :)

codigoisaac avatar Nov 10 '23 05:11 codigoisaac

This would be a great feature,hands down

Hristo-Spasov avatar Jan 12 '24 12:01 Hristo-Spasov

would love to have this feature as well

alexgoff avatar Jan 22 '24 23:01 alexgoff

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

RyanTippsTX avatar Jan 23 '24 22:01 RyanTippsTX

Any news? It would be a great feature.

AntoninoGargiuloBID avatar Feb 15 '24 15:02 AntoninoGargiuloBID

Any news? It would be a great feature.

r-josue avatar Feb 28 '24 01:02 r-josue