You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
Additionally to the common prop-types package, we could support and implement airbnb's version. It adds a lot of useful propTypes that allow us give users more context about what is possible. Even validation while editing should be possible.
and: ensure that all provided propType validators pass
foo: and([number, nonNegativeInteger])
between: provide an object with an gt or gte number, and an lt or lte number (only one item allowed from each pairs; one or both pairs may be provided), and the resulting propType validator will ensure the prop value is a number within the given range. Alternatively, you can provide a function that takes the props object and returns a number for each of the gt/gte/lt/lte values.
foo: between({ gte: 0, lte: 5 })
foo: between({ gt: 0, lt: 5 })
elementType: require that the prop be a specific type of React element - takes a Component, an HTML tag name, or "*" to match everything.
foo: elementType('span')
foo: elementType(Component)
numericString: require the prop be a string that is conceptually numeric.
foo: numericString()
or: recursively allows only the provided propTypes, or arrays of those propTypes.
foo: or([bool.isRequired, explicitNull()])
range: provide a min, and a max, and the prop must be an integer in the range [min, max)
foo: range(-1, 2)
stringEndsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that ends with it.
foo: stringEndsWith('.png')
stringStartsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that starts with it.
foo: stringStartsWith('prefix-')
valuesOf: a non-object requiring PropTypes.objectOf. Takes a propType validator, and applies it to every own value on the propValue.
foo: valuesOf(number)
The text was updated successfully, but these errors were encountered:
Additionally to the common prop-types package, we could support and implement airbnb's version. It adds a lot of useful propTypes that allow us give users more context about what is possible. Even validation while editing should be possible.
https://github.com/airbnb/prop-types
These could be especially useful:
and
: ensure that all provided propType validators passfoo: and([number, nonNegativeInteger])
between
: provide an object with angt
orgte
number, and anlt
orlte
number (only one item allowed from each pairs; one or both pairs may be provided), and the resulting propType validator will ensure the prop value is a number within the given range. Alternatively, you can provide a function that takes theprops
object and returns a number for each of thegt
/gte
/lt
/lte
values.foo: between({ gte: 0, lte: 5 })
foo: between({ gt: 0, lt: 5 })
elementType
: require that the prop be a specific type of React element - takes a Component, an HTML tag name, or"*"
to match everything.foo: elementType('span')
foo: elementType(Component)
numericString
: require the prop be a string that is conceptually numeric.foo: numericString()
or
: recursively allows only the provided propTypes, or arrays of those propTypes.foo: or([bool.isRequired, explicitNull()])
range
: provide a min, and a max, and the prop must be an integer in the range[min, max)
foo: range(-1, 2)
stringEndsWith
: takes a non-empty string, and returns a validator that ensures the prop value is a string that ends with it.foo: stringEndsWith('.png')
stringStartsWith
: takes a non-empty string, and returns a validator that ensures the prop value is a string that starts with it.foo: stringStartsWith('prefix-')
valuesOf
: a non-object requiringPropTypes.objectOf
. Takes a propType validator, and applies it to every own value on the propValue.foo: valuesOf(number)
The text was updated successfully, but these errors were encountered: