extract-react-types icon indicating copy to clipboard operation
extract-react-types copied to clipboard

Support multiple exports

Open samcooke98 opened this issue 5 years ago • 2 comments

Hi there,

I was just wondering if you'd consider supporting files that export multiple components?

I noticed in here that you just take the first component: https://github.com/atlassian/extract-react-types/blob/master/packages/extract-react-types/src/index.js#L132

I'm happy to submit a PR for this, just wanted to see if that would be something you'd be open to supporting?

Thanks

samcooke98 avatar Apr 04 '19 05:04 samcooke98

Hey Sam! Thanks for raising this issue! It's a good idea, with some design constraints/history worth knowing about before diving in to it.

We actually used to do this (on the extract-react-types side anyway, pretty-prop-types (the rendering engine) always took the first component which is not ideal).

Basically it found everything in your file that was a React.Component.

We switched this when we switched to also analysing functional components, which switched us to analysing export instead of just found components. By only looking at default, we can make an assumption that the export is a component (functional or otherwise), and analyse them like that. In fact, our logic to detect a functional component is just

https://github.com/atlassian/extract-react-types/blob/a972d1080fd03810b8338837df5c4e3e16cdbd9f/packages/extract-react-types/src/index.js#L1567-L1575

:badpokerface:

Analysing multiple exports and being confident they are all components probably means implementing real logic here that determines whether a function is a function component or not.

(Though we want to do that anyway, as extract-react-types does enough now we're thinking about pointing it at function and object signatures, as it theoretically does these anyway)

Uh, hope that helps answer your question!

The easy answer is yes, qualified by the above.

Noviny avatar Apr 04 '19 23:04 Noviny

ps. If you want to just use multiple exports now, you can via this exported function that we have failed to document:

https://github.com/atlassian/extract-react-types/blob/a972d1080fd03810b8338837df5c4e3e16cdbd9f/packages/extract-react-types/src/index.js#L1603-L1614

Noviny avatar Apr 04 '19 23:04 Noviny