reactjs / reactjs/react-docgen

Support React.Config

Open
#499 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

flow new feature
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
5h 7m
Merged PRs (30d)
4

Description

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
    }
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the functional-component example and its reported JSON output, then trace how react-docgen handles React.Config and destructured props. Done means the defaultProp, optionalProp, and requiredProp entries are all parsed with correct required and default-value metadata.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.