Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const DynamicComponent = React.lazy(() =>
import(`path/to/${reactComponentName}`)
);
return (
//This works, but now how to I crawl in and grab its properties and PropTypes?
<Suspense fallback={<div>Loading...</div>}>
<DynamicComponent title="Lazy loaded component" />
</Suspense>
)
@remy

This comment has been minimized.

Copy link

commented Mar 21, 2019

Can you elaborate on what you're doing to "crawl in and grab"?

My guess is that during your crawl process, you're looking at whatever React.lazy returns the first time around. I'd be looking for some kind of hook from React.lazy to trigger my crawling code to re-run it's process.

But that's only assuming I guessed right on what "crawl in" was.

@bradfrost

This comment has been minimized.

Copy link
Owner Author

commented Mar 21, 2019

@remy just updated the gist as I'm using the <Suspense> feature. I guess I'm looking for something like "when component has successfully loaded, do stuff like grab its PropTypes and loop through them"

@kamranayub

This comment has been minimized.

Copy link

commented Mar 21, 2019

Would this work?

https://codesandbox.io/s/o5wxz1wv29?fontsize=14

import() returns a Promise that will resolve the module; you could dive in there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.