The Proptypes in react

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.