Reputation: 8613
I tried:
PropTypes.oneOf([
PropTypes.number,
null,
]);
PropTypes.oneOfType([
PropTypes.number,
null,
]);
None of them work... how can I set a prop to be allowing either null or numbers with prop-types library in React.js?
Upvotes: 2
Views: 3681
Reputation: 8613
well, surprising, prop-types haven't able to support that ... even when someone actually already proposed the change to add isDefined
into a type..........
Here is the answer https://github.com/facebook/prop-types/pull/90
Its still await to be merged but seems functionality itself is already done. Let's push for its merge if you have the same problem!
Upvotes: 1