-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
React Suspense and react-toastify #276
Comments
Hey @goenning, I made an example with Now let me give you more details. When you call for instance Is that what you are looking for ? |
Very close, but not exactly. In your example the bundle that contains ToastContainer will be loaded async, which is a good start, but it'll still be loaded and mounted even when there was no What I'm trying to achieve is:
I think this package has 1 & 3 builtin. Number 2 is achieved with Suspense and Lazy, but how to trigger that? |
@goenning so you want to mount the |
Exactly! |
Interesting. Something just came to my mind now. To achieve code split, we need to wrap both toast and ToastContainer on an async module. Because if we import "react-toastify" on any other component (like App.js on your example), webpack will bundle it as sync bundle, which defeats the purpose of code splitting. But you gave me some ideas, I'll try it out, see how it goes and update this thread. Thanks! |
You're welcome! |
For anyone interested: https://github.com/goenning/example-react-toastify-code-split This project will only load react-toastify library when the user clicks on the logo for the first time. If react-toastify supported React Portals, the solution would be slightly simpler, as we wouldn't need to mount the ToastContainer. Maybe that could be a new feature request? 😄 |
Hey @goenning, How will I would love to hear more about your idea. |
Well, I don't know much about react-toastify internals, but as far as I understood, If toast("Hello World", {
// ...options
renderTo: "root-toastify"
}
I haven't done much with React Portals, but I guess that's what it is for. |
@goenning I really like the idea of having a This also allow to render the I see one downside with this approach. Some props are only available for the Thank you for the brilliant idea( |
Just for reference, I have implemented it on a real app and it works 💯 This is how we did it getfider/fider#645 |
This is very neat. I'll probably start to work on the next release in 2 weeks. I'll leave the issue open with a label how to. Thank you for sharing your solution |
Hey @goenning, For the next release the |
Is there any way to use react-toastify with React.lazy?
My scenario is that there are very few places we show the toaster, probably only 5% of the users ever see a toaster. As of now, we push react-toastify on the main bundle, forcing everyone to download it.
I'm thinking on how can we use React.lazy to solve this, but I can't don't know how would I do it, mostly because the toast function requires to be on the DOM when it's called.
Any thoughts on how to achieve this?
Thanks!
The text was updated successfully, but these errors were encountered: