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

Support generate doc with imported component #28

Closed
Stupidism opened this issue May 30, 2017 · 5 comments
Closed

Support generate doc with imported component #28

Stupidism opened this issue May 30, 2017 · 5 comments

Comments

@Stupidism
Copy link

Stupidism commented May 30, 2017

A member of them said this is possible in this issue
reference doc is here

@danielduan
Copy link
Member

I'm not sure what you're asking for here. With this plugin configured with babel, when you access a component via the import or require, you should be able to see the docgen info.

const Component = require('./component.jsx');
console.log(Component.__docgenInfo);

@Stupidism
Copy link
Author

// Button.js
Button.propTypes = {
  /*
   *  callback when button is clicked
   */
  onClick: PropTypes.func,
}

export default Button;

// ButtonWithColor.js
import Button from './Button';
export withColor(Button);

Then the description info is lost.

const ButtonWithColor = require('./ButtonWithColor');
console.log(ButtonWithColor.__docgenInfo);

@danielduan
Copy link
Member

There's no way around this unfortunately. react-docgen only supports getting proptype info from the component file itself, not any imported components or proptypes.

I think its a limitation of react-docgen itself, but if you find a solution, please open a PR. I would love to see that implemented.

@Stupidism
Copy link
Author

@danielduan But here it says hoc is OK.

Detect exported components passed to HOCs
Until now, react-docgen didn’t find components that are passed to a higher order component (HOC):

function MyComponent() { /* ... */ }
export default hoc(MyComponent);

The workaround was to change the resolver to find all component definitions in the file, something that is not always desirable.
With #124, @ rtsao extended the default resolver to be able to handle these cases.

@danielduan
Copy link
Member

I think their case is when the HOC is in the same file.

Their tests are all contained in the same file:
https://github.com/reactjs/react-docgen/pull/124/files

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

No branches or pull requests

2 participants