Open iamdustan opened 8 years ago
You mean why it isn't listed in the README? Probably just an oversight from my side.
wait. does the displayName already appear in there?
I don’t think it does... this is the result of console.logging
docgen.parse(fs.readFileSync('./my-component.js'))
{ description: '@private',
props:
{ to: { type: [Object], required: true, description: '' },
name: { type: [Object], required: true, description: '' } } }
I can't repro this btw. The displayName
shows up in the result. What does your ./my-component.js
look like?
Hmm..
so I have stateless components not getting a displayName
as well as
import React, {PropTypes, Component} from 'react';
class Tabs extends Component {
....
}
export default Tabs;
Oh, the displayName
handler only looks for explicit displayName
properties. You want it to also return the inferred name from the class or function name, right?
:+1:
...does babel still follow that approach for displayName handling?
@fkling, yes! (I know the question wasn't to me, but I'd love to have it this way :))
I don't know, will have to look into this. Seems reasonable to me though. PRs are also welcome ;)
I vote @mik01aj for those one :)
Babel will generate the display name for you when it is not supplied explicitly.
:+1: to implementing a similar inferrance rule to react-docgen
@iamdustan Would this be something that is feasible to implement?
Maybe you could just use this plugin: https://github.com/gajus/babel-plugin-react-display-name
I would love for react-docgen to be able to infer the name of a component based on the Component.name.
Babel only creates a displayName for the .createClass()
convention, not for the es6 classes or stateless functional components.
I'll dig around react-docgen today and see if I can figure out a PR that might accomplish this.
Is there a reason this wasn’t already included? Having a displayName with each description would be beneficial for tools that are using docgen without having to re-read the js file to detect the display name again.
This wasn’t that big of a deal with
React.createClass
orclass extends React.Component
since those are pretty limited call sites, but the stateless function components can get a bit gnarly in trying to infer their display names. The detection for these are already pretty solid in the #28 branch.