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

Dynamically Importing Components with React.lazy #106

Open
AleksandrHovhannisyan opened this issue Sep 5, 2021 · 4 comments
Open

Dynamically Importing Components with React.lazy #106

AleksandrHovhannisyan opened this issue Sep 5, 2021 · 4 comments
Labels
comments Comments section for an article.

Comments

@AleksandrHovhannisyan
Copy link
Owner

No description provided.

@AleksandrHovhannisyan AleksandrHovhannisyan added the comments Comments section for an article. label Sep 5, 2021
@kocendavid
Copy link

Hi in your article you mentioned

One workaround is to re-export those modules as default exports from an intermediate module.

How would that look like?
Thanks!

@AleksandrHovhannisyan
Copy link
Owner Author

@kocendavid Oh, I should probably link to the React docs in my article. Here's the relevant bit: https://reactjs.org/docs/code-splitting.html#named-exports

@ianfeldberg
Copy link

@AleksandrHovhannisyan great article! I am trying to get something similar working except I need to dynamically load a React component from an npm package that I won't know until runtime. I have a component that draws a simple frame with some controls on it and is in package A. What I want to do is - at runtime - load up all the React components in packages B, C, and D and drop them in the frame. Is there any way of dynamically loading a React component unless it's been npm imported into package A ahead of time?

Think Java interfaces. I can define an interface and put it in one jar file and then implement that interface and stick it in another jar file. At runtime, as long as both JAR files are on the classpath, it all works great. Is there anything in the JS/React world that works that way?

@AleksandrHovhannisyan
Copy link
Owner Author

@ianfeldberg Unfortunately, I can't really say without seeing some sample code. Note that you can lazily import both internal modules and npm modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comments Comments section for an article.
Projects
None yet
Development

No branches or pull requests

3 participants