Specify Valid Children Component Types
I was expecting to be able to use PropTypes.instanceOfto specify valid children types, like so:
static propTypes = {
children: PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.instanceOf(ComponentOne),
PropTypes.instanceOf(ComponentTwo)
]))
}
I got a relatively obscure error: Failed prop type: Right-hand side of 'instanceof' is not an object
After some searching, stumbled on: https://github.com/facebook/react/issues/2979
The explanation/reason for closing being that instanceOf doesn't work on components. Okay, so would still like to achieve the end goal somehow. https://github.com/facebook/react/issues/2979#issuecomment-219610493 is actually pretty slick.
Just specifying PropTypes.element is not sufficient, IMO.
I'm assuming this is a feature request, but maybe I'm overlooking something. TIA.
In the meantime, try childrenOfType in https://npmjs.com/airbnb-prop-types.
Is this open for a PR? Or are there things we still have to discuss/agree on? Would be nice to have this.
It doesn’t have the help wanted label, so it’s not open for PR (ie, you can make one, but there’s no guarantee it’d be accepted)
I see. Why is there no help wanted label if I may ask? Are there objections to adding this?