Support Object.assign in propTypes definition

Open
#151 9 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

No source file or test is named. Start by tracing how react-docgen evaluates component propTypes, then reproduce the Object.assign example from the issue. Done means inherited and locally defined propTypes are both extracted correctly, with a regression test covering the example.

Written by the indexing model from the issue text.

Description

improvement

In my React App, I have components which pass receive properties but just pass them as is to their child component. The parent component sort of extends the child component properties, so I'm using Object.assign to avoid code duplication. Unfortunately, recat-docgen doesn't seem to handle propTypes values which are evaluated from a function.

For example, let's say I have a component named ParentComponent and a component named ChildComponent.

The render function of the ParentComponent looks like this:

render() {
  return (
    <ChildComponent childPropA="SomeValue" childPropB="AnotherValue" />
  );
}

When I render the ParentComponent my code looks like this:

<ParentComponent parentPropA="Value" childPropA="SomeValue" childPropB="AnotherValue" />

Therefore, I use Object.assign for setting ParentComponent.propTypes:

ParentComponent.propTypes = Object.assign({}, ChildComponent.propTypes, {
  parentPropA: React.PropTypes.string
});
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
3h 28m
Merged PRs (30d)
6

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.

More from reactjs/react-docgen

All issues in reactjs/react-docgen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.