Sometimes, you might find it useful to extract information from your React components on runtime using their
propTypes. However, this can be tragically difficult to extract meaningful information from because
PropTypes is just a collection of functions.
Using this module adds additional properties onto the PropType validators, which you can use to extract extra information about what the propTypes actually are.
The following properties are exposed on every PropType:
typeName- Matches the name of the validator on
PropTypes, such as
string, 'bool', 'oneOf', etc.
.isRequiredwas used in the propTypes definition, this is true. Otherwise, it is false.
For PropTypes that you pass an argument to (such as
oneOf), there's an additional property:
typeChecker- The argument that you passed to the PropType function.
;;console; // 'string'console; // falseconsole; // trueconsole; // 'oneOf'console; // falseconsole; // ['hello', 'world']console; // true