Data type checking pass the value ProtoTypes assembly React

  Check basic types :

  Previous cases, the data transfer to the parent component sub-assembly there, and do not check the data type

  

  Although the proper delivery and use, but does not do sub-assemblies in the type of validation data transfer, that is, at this time we will not pass any value error.

Rich experience in the development of small partners know, when the complexity of a larger project, if we do not do the type of data validation, late is prone to a mistake, the " business logic error ."
Business logic errors are generally in the development of the most difficult to find errors, data transfer may be passed to a problem, the problem not easy to find syntax errors, in order to avoid such errors, we have the data in the development of school experience.
React case will need the aid of a prop-types, as shown below, in sub-assembly is introduced verification objects and verification

  

 

 

   Note here that the nomenclature PropTypes is commonly known as the default, in order to facilitate teamwork, usually known as the default naming

  

  At this point it would be for the type of data transfer made the corresponding check, if you do not comply with the data type warning appears in the console

  Required check : Next add other data as follows

  

  If parent element is not transmitted data, this time is not given prompt. This is clearly not in line with the development of specifications

  

 

  Then do the required verification: a string type and data transfer is required.

  

  The next error will not be passed

  

  

 

  Default settings check :

 

   

Guess you like

Origin www.cnblogs.com/jianxian/p/12456819.html