Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple <Toaster> elements #158

Open
mrmiguu opened this issue Mar 5, 2022 · 24 comments · May be fixed by #383
Open

Support multiple <Toaster> elements #158

mrmiguu opened this issue Mar 5, 2022 · 24 comments · May be fixed by #383
Labels
enhancement New feature or request

Comments

@mrmiguu
Copy link

mrmiguu commented Mar 5, 2022

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 timolins added the enhancement New feature or request label Mar 6, 2022
@timolins
Copy link
Owner

timolins commented Mar 6, 2022

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
Copy link

This would be super helpful.

@TrejoCode
Copy link

Please, consider, would be amazing feature

mrmiguu added a commit to mrmiguu/react-hot-toast that referenced this issue Mar 11, 2022
…s by id

# What

`<Toaster>` and `toast()` currently have no way of communicating
distinctly if there exists multiple Toaster elements throughout. Add a
way for toast calls to "pop up" exclusively from any specific Toaster

# Changes

Add `toasterId` to `<Toaster>` props

Add `toasterId` to all `toast*()` calls under the `options?` arg
@mrmiguu
Copy link
Author

mrmiguu commented Mar 11, 2022

#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
Copy link

looking forward to having this!

@bolerap
Copy link

bolerap commented Nov 10, 2022

hi all,
how about this

@mattellig
Copy link

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

@Mirajjj
Copy link

Mirajjj commented May 9, 2023

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

@Benimation
Copy link

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
Copy link

Any updates on this?

@Arcanorum
Copy link

pls ser?

@eugene-f02
Copy link

This would be an extremely valuable feature!

@sspenst
Copy link

sspenst commented Nov 4, 2023

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

@codigoisaac
Copy link

Please consider this feature :)

@Hristo-Spasov
Copy link

This would be a great feature,hands down

@alexgoff
Copy link

would love to have this feature as well

@RyanTippsTX
Copy link

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

@AntoninoGargiuloBID
Copy link

Any news? It would be a great feature.

1 similar comment
@r-josue
Copy link

r-josue commented Feb 28, 2024

Any news? It would be a great feature.

@emilywilder
Copy link

Just wanted to add my interest in this feature

@fccjr24
Copy link

fccjr24 commented May 3, 2024

need this too

@georgiosApo
Copy link

georgiosApo commented May 6, 2024

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

@fellypsantos
Copy link

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.

@timolins
Copy link
Owner

timolins commented Jan 6, 2025

I started a PR (#383) for this! You can follow along there. 🎉

The WIP docs + demo can be viewed here: https://react-hot-toast-git-multi-toaster-timos-team.vercel.app/docs/multi-toaster


Edit: I just published v2.6.0-beta.0, which adds support for multiple toasters. You can give it a try with npm i react-hot-toast@beta. Testers and feedback are much appreciated.

Try it out: npm i react-hot-toast@beta

@timolins timolins linked a pull request Jan 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.