-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Proposals for new React.PropTypes #6166
Comments
actually I don't sure PropTypes.range is a good idea because prop may become invalid only in production and this will lead to potential errors when developers rely on PropTypes and don't validate props inside their components but I'll leave this proposal here for further discussion |
@chicoxyzzy PropType checking is disabled in production |
@yaycmyk sure. That's why devs may not have warnings in production and if they do not validate data in their components this will lead to potential production-only errors which is bad thing |
Yeah, I also just took a second look over all the current |
Why do you have a prop that is either a string or |
|
Currently, as far as I know there are no plans to add new features to See #3510 (comment). |
@JustBlackBird That's what |
@rmilesson, then you can treat it as "string or It actually does not matter. The point is to explicitly pass "no value" to component. |
@JustBlackBird My point is that you should not use strings and booleans interchangeably. I mean, you can, absolutely, but it's pretty bad form. |
Ok, you've got you. Even if I want to use PropTypes.oneOfType([
PropTypes.string,
PropTypes.oneOf([null])
]); (So it does not matter And this proposal is about adding |
No. Not at all.
Edit: A better approach would be to allow |
That is the point. |
@JustBlackBird If it was forgotten by accident, it would be Proptypes are mostly legacy and in maintenance mode, having been replaced by tools like Flow. My guess is we aren't going to add this, so let's close it out. We can re-open if our thinking on this matter changes substantially. It is worth noting that proptypes are just validator functions. You can define your own, and share/distribute your own proptypes. This is the optimal outcome, because people can download the additional proptypes if they find them useful. |
PropTypes.exactly
I took use case below from some gitter chat where @JustBlackBird wanted some property to be
String
or exactlyfalse
. So maybe he can add some comments here.Use case
instead of
PropTypes.range
It is very common case when we need prop to be a Number in some range. Let's say it should be percent value from 0 to 100 or other inputs with type range for example.
Use cases:
or even
Another example
The text was updated successfully, but these errors were encountered: