reactjs / reactjs/react-docgen

Support Object.assign in propTypes definition

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

Nobody has claimed this yet.

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

Description

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

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

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.

Assessment

Tech stack
javascript, react
Domain
documentation, tooling
Issue type
Feature
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.