Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Add a PropTypes for React elementType (ie. MyComponent) #211
There is a missing prop type that is quite common for a lot of people:
ForwardRef in 16.3
However, with new features since React 16.3, there is a new challenge: forward ref!
The problem with this:
To fix this, I've added
Higher-Order Component (HOC)
The reason why this prop type is so important to add is because of HOC. If you're using a library HOC, as soon as you add the decorator on your component using
What should be a component?
First we need to support regular stateless and stateful component. The best way to do that is by checking if it's a function. I don't think we can do better here unfortunately because of stateless components.
Then, there is special cases created by React like the forward ref. Here are all the
Forward ref is the most obvious use-case, but the context provider/consumer are technically component created by React. I just don't think it would be used much in a prop though.
Here are my main concerns with this PR:
Bumping React version to 16 in devDependencies
The tests were running on the old 15 version of React, I'm guessing to make sure we don't break the old version. However, to test forward ref and the context API, we need at least React 16.3. I've updated the version, but an alternative would be to have two different package with the different version. Is it worth it? Also, should we bump the version of prop-types to 16? There is no breaking change, but the tests would be running on that version unless we run the tests on both by adding a proxy package pointing to React 15.
Should we really call that new prop type component?
I think it's the best name, but in the previous code, the prop type element (and sometimes node) were referred as component. To me, a React component is
EDIT: Been renamed
Where I've added
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.
If you have received this in error or have any questions, please contact us at firstname.lastname@example.org. Thanks!
BTW, we've had this implemented in prop-types-extra as