-
Notifications
You must be signed in to change notification settings - Fork 123
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
How to lazy load a mui dialog in nextjs when it's open? #107
Comments
For anyone stumbling on this in the future: https://nextjs.org/docs/advanced-features/dynamic-import |
Here's what I came up with: import NiceModal from "@ebay/nice-modal-react";
import dynamic from "next/dynamic";
const LoginModal = dynamic(() => import("components/Modals/LoginModal").then((mod) => mod.LoginModal));
// Register lazy modals here
const LoginModalWrapper = () => <LoginModal id="login-modal" />;
NiceModal.register("login-modal", LoginModalWrapper);
// Use them in inner components
NiceModal.show("login-modal"); This method helped me reduce 200 KBs from the initial JS load in my app. |
Just curious, why not just use |
I think that example is incomplete? I can't see what adds the lazy loading, unless I'm missing something. |
@philwolstenholme @supnate You're right, I apologize for the incomplete example. I edited the code to include the dynamic import. |
Hi, I have a bunch of mui dialogs and I want to lazy load them only when they get opened. How can I do that in nextjs?
The text was updated successfully, but these errors were encountered: