PropType Conditionals
A React PropType utility library that consists of various custom proptype validators.
Installation
$ npm install --save prop-type-conditionals
Usage
You may import the individual validators as needed or you can import the entire module:
// Import individual validator // Import entire module
Methods
isAllowedIfNone
Returns a function that validates that the prop is not defined if any of the exclusive props are already defined. The .isRequired
chained validator specifies that the prop is required if none of the exclusive props are defined.
@param {Array[String]} exclusivePropNames
@param {PropTypes.validator} validator
ComponentpropTypes = foo: PropTypesstring bar: PropTypesstring baz:
isOneOfType
Returns a function that validates that the prop's type matches one of the component constructors or element type specified. If this validator is used on the children
prop, it validates that all child components pass validation.
@param {Array} allowedTypes
ComponentpropTypes = children:
isRequiredIf
Returns a function that validates that a prop is required if the condition function returns true
.
@param {Function} condition
@param {Function} validator
const condition = true ComponentpropTypes = foo:
isValidIf
Returns a function that validates that the prop passes the user defined condition.
@param {Function} condition
@param {PropTypes.validator} defaultValidator
const condition = true ComponentpropTypes = foo:
isWholeNumber
Returns a function that validates that the prop is a whole number
ComponentpropTypes = foo: