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 React.Config #499

Open
yanyanzai opened this issue Apr 15, 2021 · 2 comments
Open

Support React.Config #499

yanyanzai opened this issue Apr 15, 2021 · 2 comments

Comments

@yanyanzai
Copy link

yanyanzai commented Apr 15, 2021

For functional components we can use React.Config to define default props:

import * as React from 'react';

type DefaultProps = $ReadOnly<{
  /** Description for defaultProp. */
  defaultProp: number,
}>;
type AllProps = $ReadOnly<{
  ...DefaultProps,
  /** Description for optionalProp. */
  optionalProp?: number,
  /** Description for requiredProp. */
  requiredProp: number,
}>;
type Props = React.Config<AllProps, DefaultProps>;

export default function Component({
  defaultProp = 0,
  optionalProp,
  requiredProp,
}: Props) {
  return <div />;
}

But react-docgen fails to parse all the props properly. It only parses the default prop but not the other two props.

{
  "description": "",
  "displayName": "Component",
  "methods": [],
  "props": {
    "defaultProp": {
      "defaultValue": {
        "value": "0",
        "computed": false
      },
      "required": false
    },
    "optionalProp": {
      "defaultValue": {
        "value": "0",
        "computed": false
      },
      "required": false
    }
  }
}
@danez
Copy link
Collaborator

danez commented Apr 15, 2021

Is this a flow or typescript feature?

@yanyanzai
Copy link
Author

This is a flow feature. See reference here: https://flow.org/en/docs/react/types/#toc-react-config

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

No branches or pull requests

2 participants