Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

how to do default props? #5

Closed
tsiq-swyx opened this issue Feb 12, 2018 · 8 comments
Closed

how to do default props? #5

tsiq-swyx opened this issue Feb 12, 2018 · 8 comments

Comments

@tsiq-swyx
Copy link

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
Copy link
Owner

strothj commented Feb 13, 2018

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
Copy link
Author

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
Copy link
Owner

strothj commented Feb 13, 2018

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

Let me know if it works for you

@tsiq-swyx
Copy link
Author

yes!!

image

image

@city41
Copy link

city41 commented Jun 27, 2019

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
Copy link
Owner

strothj commented Jun 28, 2019

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

@GabeDuarteM
Copy link

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

const Component: FunctionComponent<
    Props
> = ({ optionalPropWithDefault = [] }) => {
    [...]
}

@ffloyd
Copy link

ffloyd commented Jan 5, 2020

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.

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

No branches or pull requests

5 participants