Comments (11)
Because we didn’t have a use case for anything but the complete check.
What’s your use case?
from prop-types.
Can you use childrenOf(withShape(PropTypes.element, { stepName: string.isRequired })).isRequired
?
from prop-types.
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.
from prop-types.
Closing pending confirmation.
from prop-types.
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.
from prop-types.
so <div stepName="not a real step" />
would be valid?
from prop-types.
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.
from prop-types.
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?
from prop-types.
yep, exactly.
from prop-types.
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.
from prop-types.
@Asday with the latest version of prop-types
(facebook's), is this still an issue?
from prop-types.
Related Issues (20)
- childrenOfType incompatible with projects using react-hot-loader HOT 2
- requiredBy missing on npm? HOT 3
- pass-through prop-type validators HOT 1
- Pass an array of components to childrenOfType? HOT 2
- how to check if 1 prop is set? HOT 3
- Regex proptype validation ? HOT 4
- expose prop-types as object collection instead of function HOT 1
- Children of children / recursive validation HOT 3
- SyntaxError: Unexpected identifier on `forbidExtraProps` from `prop-types-exact` HOT 1
- SyntaxError: Unexpected identifier on `forbidExtraProps` from `prop-types-exact` HOT 1
- mutually exclusively require prop HOT 2
- `mutuallyExclusiveProps` is unintuitive / poorly documented
- What do you think about stringEndsWith? HOT 7
- Generating documentation HOT 1
- `componentWithName` fails when used with `childrenOf` and `forwardRef` HOT 2
- Check for children of fragments in `childrenOfType` validator HOT 1
- React 17 peer support HOT 11
- forbidExtraProps seems to have no effect HOT 2
- SyntaxError Unexpected end of script at `t.getComponentName(airbnb-prop-types/src/helpers/getComponentName)` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prop-types.