Comments (6)
Here's what I came up with:
import NiceModal from "@ebay/nice-modal-react"; import dynamic from "next/dynamic"; // 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
NiceModal.register("login-modal", LoginModal);
without wrapper.
It gives a type mismatch
![image](https://private-user-images.githubusercontent.com/57867800/242582801-c5842b16-b6cd-4a90-975e-2063f6b256b5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5ODU4MDUsIm5iZiI6MTcxOTk4NTUwNSwicGF0aCI6Ii81Nzg2NzgwMC8yNDI1ODI4MDEtYzU4NDJiMTYtYjZjZC00YTkwLTk3NWUtMjA2M2Y2YjI1NmI1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAzVDA1NDUwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM5ZTdmNWU2YmM1YjBhZTFiYThlN2Q1MWY3OWRiOGYwNGRjZGU5N2VmZTA5Y2RhNDViNzI4MTZlMDNiNWZjNGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.stDSMjTYF7zhh-irCglpgtVqc8NB0aAJTVoUUh3-L1w)
from nice-modal-react.
For anyone stumbling on this in the future:
https://nextjs.org/docs/advanced-features/dynamic-import
https://beta.nextjs.org/docs/optimizing/lazy-loading
from nice-modal-react.
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.
from nice-modal-react.
Here's what I came up with:
import NiceModal from "@ebay/nice-modal-react"; import dynamic from "next/dynamic"; // 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 NiceModal.register("login-modal", LoginModal);
without wrapper.
from nice-modal-react.
Here's what I came up with:
import NiceModal from "@ebay/nice-modal-react"; import dynamic from "next/dynamic"; // 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
NiceModal.register("login-modal", LoginModal);
without wrapper.
I think that example is incomplete? I can't see what adds the lazy loading, unless I'm missing something. dynamic
is imported from Next but not used?
from nice-modal-react.
@philwolstenholme @supnate You're right, I apologize for the incomplete example. I edited the code to include the dynamic import.
from nice-modal-react.
Related Issues (20)
- Disable body scroll lock and react portal HOT 1
- Is this library able to be used with Next.js 13 and App router? HOT 5
- Type regression in 1.2.9 HOT 13
- remove() Function without Modal ID just like hide() HOT 2
- Refactor modalHandler into a React Hook HOT 2
- [Request] Add default to remove modal HOT 3
- [Request] Improve typing of modal props HOT 5
- Antd "visible" prop is deprecated, use "open" instead HOT 1
- [deep loop] Can't use in component? HOT 1
- hide Promise does not resolve if Modal is already hidden HOT 1
- Add removeAll() method HOT 2
- Using nested NiceModalProvider for new window HOT 3
- Removing modal on page route change HOT 10
- resolveHide function not working HOT 1
- not working for multi-instance with wrap Context
- defaultVisible HOT 2
- Can the show method intelligently prompts those parameters?
- How to bind props update via use NiceModal.show(MyModal, { loading, onOk }) HOT 4
- disable hide on outside click HOT 3
- Unnecessary re-render when showing multiple modals.. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nice-modal-react.