[React log] 07-Further use plug-ins to standardize props data types

1: Source of information https://www.npmjs.com/package/prop-types uses third-party prop-types to process props to make props appear to have data type constraints (js is the probability of weak language without data types)

2: install

npm install --save prop-types

3: Use to introduce where it is needed (Header.js)

Insert picture description here

4: do a test

I will pass a number to the Header in index.js and try to rewrite the code in index.js as follows. You can also write useage={18}
Insert picture description here

5: The result of running the code will not be wrong, the page effect will come out, but the console will report an error

Insert picture description here

6: Change to

 static propTypes={
    
    

        useage:PropTypes.number

    }

The error will go away

7: Common data types are

Insert picture description here

Guess you like

Origin blog.csdn.net/u013034585/article/details/106535858