Default attributes and type checking

Property Default

Through a static property defaultPropstold react property defaults

Property type checking

Using the library:prop-types

Use the static properties of the component propTypestold how to react to check property


PropTypes.any: // any type
PropTypes.array: // array type
PropTypes.bool: // Boolean
PropTypes.func: // function type
PropTypes.number: // numeric types
PropTypes.object: // object type
PropTypes. string: // string type
PropTypes.symbol: // symbol type

PropTypes.node: // anything that can be rendered content, strings, numbers, React elements
PropTypes.element: // react element
PropTypes.elementType: // react element type
PropTypes.instanceOf (constructor): // must be specified instance constructor
PropTypes.oneOf ([xxx, xxx]) : // enumeration
PropTypes.oneOfType ([xxx, xxx]) ; // attribute must be an array type in which a
PropTypes.arrayOf (PropTypes.XXX): // must be composed of an array of a type
PropTypes.objectOf (PropTypes.XXX): // objects by the value of a certain type of composition
PropTypes.shape (object): // attribute must be an object, and satisfies the requirements specified object
PropTypes .exact ({...}): // object must exactly match the data transfer

Custom properties // check if there is an error, an error is returned to the object
attributes: function (The props, propName, componentName) {
// ...
}

Guess you like

Origin www.cnblogs.com/CoderZX/p/11923939.html