Skip to content

propTypes & defaultProps removed from decorated components #156

Description

@thany

Say I've got this component:

const Awesome = props => <div>awesomeness</div>;

Awesome.propTypes = {
  title: PropTypes.string
};

It really doesn't matter.

I export this component wrapped in the track decorator:

export default track(() => ({
  eventCategory: 'Awesome',
  eventAction: 'Awesome action',
}))(Awesome);

Then, in a different component, let's call it Tremendous, I'm trying to inherit propTypes from Awesome into Tremendous.

const Tremendous = ({awesomeProps}) => <Awesome {...awesomeProps} />;

Tremendous.propTypes = {
  awesomeProps: PropTypes.shape(Awesome.propTypes)
};

This won't work. In the above example, Awesome.propTypes is undefined. The reason for this is the track decorator. Had I not used it, I could inherit the propTypes like above, just fine.

TL;DR: The track decorator should copy/preserve propTypes and defaultProps.

Versions:
React 16.13.1
React-tracking 7.1.0
Node.js 12.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions