New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PropTypes: define children component type #1836
Comments
Used to work. Will no longer work with the upcoming descriptor changes. @sebmarkbage has some ideas. |
There are two pieces to this. The simple one is when you are expecting a single component. We should have a special propType for this. propTypes: {
header: React.PropTypes.componentOf(OtherComponent)
} That's simple. Someone send a pull-request? The second part is if you want to accept one of several unknown components that are considered compatible. In XHP in Hack we use something called categories. The third part is when you want to combine these two types of checks with a set of items. What if you want to allow a union type? What if you want the first item to be of a certain type and the remaining items another type? @azich has some ideas around this. |
Another case is if you want to accept any composite that renders to a |
It would be really cool to be able to verify that the right React component was passed in as a property. The docs are a little confusing, because it looks like you should be validating that the right React Message component is getting passed in: // An object that could be one of many types
optionalUnion: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number,
React.PropTypes.instanceOf(Message)
]), http://facebook.github.io/react/docs/reusable-components.html |
Yea, the current work around is something like: I think we need a broader solution than testing for specific types. Usually you want it to correspond to some specific interface but the actual implementation is flexible, or have a certain set of props defined on it. |
Is there any news on that? |
Proptypes are being phased out in favor of tools like Flow. |
At least part of this is something we should "maintain". |
Looks like this could be closed, the explanation is here: #7119 |
In case somebody needs this functionality, I published a module for that https://www.npmjs.com/package/react-element-proptypes |
Added a pr for this feature |
I was looking for something like:
However this doesn't work of course and couldn't find another way of doing this.
Would be nice if this was supported.
The text was updated successfully, but these errors were encountered: