Skip to content

Support Object.assign in propTypes definition #151

@danielgefen

Description

@danielgefen

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions