This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 358
null props considered differently in getDefaultProps vs. isRequired #110
Comments
Thanks for linking this issue! Interesting that 39 people reacted with a thumbs up to There's a lengthy discussion about the topic of null props going on in the PR: #90 |
For those interested in a workaround, you can always define your own propTypes: // Number or null
foo: function(props, propName, componentName) {
if (props[propName] !== null || typeof props[propName] !== 'number')
return new Error(
'Invalid prop `' + propName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
} And it is perfectly possible to make it re-usable as it is a function. |
@KeitIG I think the issue is that people prefer an out of box solution to handle such a common use-case. |
I totally agree, I am just leaving this solution in case of someone not knowing how to tackle this in the meantime. (like me, this morning). |
The check should be foo: function(props, propName, componentName) {
if (props[propName] !== null && typeof props[propName] !== 'number')
return new Error(
'Invalid prop `' +
propName +
'` supplied to' +
' `' +
componentName +
'`. Validation failed.'
);
}, |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Moving from the React repo, original issue: facebook/react#2166
The text was updated successfully, but these errors were encountered: