Closed Asday closed 4 years ago
Because we didn’t have a use case for anything but the complete check.
What’s your use case?
Might be silly? Hopefully you'll be able to tell me.
Writing a <Wizard />
that expects to be passed children with a unique (to the wizard) stepName
prop. Currently my thinking is and([childrenHaveProp('stepName'), childrenPropsAreUnique('stepName')])
or something similar would be elegant.
so <div stepName="not a real step" />
would be valid?
I don't see why not. That sort of functionality would be useful for showing an interstitial page like YouGov's "on to a different topic..." pages in their surveys.
Can you use childrenOf(withShape(PropTypes.element, { stepName: string.isRequired })).isRequired
?
Ooh, that looks very promising. So that's essentially the childrenHaveProp()
in my conjectural example I think?
Is the .isRequired
on childrenOf()
making it so at least one is required?
yep, exactly.
Well gosh I think that's that then.
I feel like this issue kinda took a walk away from what I was originally askin', 'cause I was asking the wrong thing. I still think it's appropriate to close though, as my issue has been solved, so I bid you adieu, and thanks.
Sorry, I'm back - that doesn't appear to work. As a cut down example:
class Wizard extends Component {
static propTypes = {
children: childrenOf(withShape(
PropTypes.element,
{ stepName: PropTypes.string.isRequired },
)).isRequired,
}
render = () => null
}
<Wizard><Text stepName="First">First</Text><Text stepName="Last">Last</Text></Wizard>
raises Warning: Failed prop type: The prop
stepNameis marked as required in
Wizard, but its value is
undefined`. Dropping the
stepName` prop from either or both of the children results in the same message.
It looks like prop-types
(facebook's, not yours) is checking for stepName
on <Wizard />
rather than its children, but I'm not smart enough to figure out if that's true, and/or why.
I've renamed the issue to make more sense given the direction it took.
@Asday with the latest version of prop-types
(facebook's), is this still an issue?
Closing pending confirmation.
Why does there exist a rather complex prop-type that checks three conditions, without those conditions being individually available, while
and
exists?If there's not a reason, might I open a PR?