Proptypes is used to standardize the types that props must satisfy, and if validation does not pass there will be a warn hint.
The types of React proptypes are:
React.PropTypes.array//Queue React.PropTypes.bool.isRequired//Boolean and must be React.PropTypes.func//function re Act. Proptypes.number//Digital React.PropTypes.object//Object React.PropTypes.string//String react.proptypes. Node//Any type: numbers, strings, elements or array React.PropTypes.element//React element React.PropTypes.instan CeOf (XXX)//some type of XXX object React.PropTypes.oneOf ([' foo ', ' Bar '])//One of the string React.PropTypes.oneOfType ([ React.PropTypes.string, React.PropTypes.array])//One of the types React.PropTypes.arrayOf (React.PropTypes.string)// An array of some type (string) React.PropTypes.objectOf (React.PropTypes.string)//element is the object of the string React.PropTypes.shape ({ Whether the object conforms to the specified format color:React.PropTypes.string, fontSize:React.PropTypes.number}); React.PropTypes.any.isRequired//Can be in any format and necessary. Custom format, non-conforming when put back error//do not use ' console.warn ' or throw, because it is invalid in the case of ' oneoftype ' customproptype:function (props, propname, ComponentName) {if (!/^[0-9]/.test (Props[propname]) {return new Error (' Validation failed! '); }}
The Proptypes in react