strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

how to do default props? #5

Closed tsiq-swyx closed 6 years ago

tsiq-swyx commented 6 years ago

hello! i have a very basic question... how do i make default props show up in here?

image

the styledguidist folks dont document this either and i was just hoping for a pointer!

thank you again!

strothj commented 6 years ago

Hello,

There was an oversight on my part. I need to fix the plugin to support it. The loader version supports it.

In the prop description:

interface Props {
  /**
    * @default green
    */
  color?: "blue" | "green";
}
tsiq-swyx commented 6 years ago

ok so if i read that right this is something to fix as I currently don't see this working in my version. i'll leave this issue open in case you want to track it. thanks again, you're awesome

strothj commented 6 years ago

I've uploaded v1.1 that has the support.

Let me know if it works for you

tsiq-swyx commented 6 years ago

yes!!

image

image

city41 commented 5 years ago

Will default values always be surrounded by quotes? I feel for the above delay1, the default value shoudl be 250, not "250". Is it possible to accomplish that?

strothj commented 5 years ago

@city41 I opened a new issue to track this. I don't like those quotes either.

GabeDuarteM commented 4 years ago

@strothj can't we automatically infer the default, in components such as the one below?

const Component: FunctionComponent<
    Props
> = ({ optionalPropWithDefault = [] }) => {
    [...]
}
ffloyd commented 4 years ago

I'm also very interested in ability that @GabrielDuarteM mentioned.

Without it I'm forced to violate Don't Repeat Yourself principle because I have to write same value in two places. In such circumstances It's too easy to change values in the code but forget to change it in documentations. Especially for components with significant amount of props.

Situation may get even worse if you have some props interface which is built from extending another interface. With functional components I'm defining defaults inside function signature (it's most natural way for me). When doing this, default in docstring and function signature inside different files.

Moreover, some people like to store types (and proptypes) inside separate from component's one file.