ey dee ey em
ey dee ey em

Reputation: 8613

How to add a proptypes of either null or number in React.js with prop-types library

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

Answers (1)

ey dee ey em
ey dee ey em

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

Related Questions