markdown 40 - 验证道具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 40 - 验证道具相关的知识,希望对你有一定的参考价值。

- better way of handling props, mostly if you write components that might be used by other developers
- can restrict the types and values that you receive for your props
- Person receives four important props: click, name, age, changed
- there is an extra package that you can add for this
- cmd `npm install --save prop-types`
- provided by react team, allows us to check the type of our property
- import statement: `import PropTypes from 'prop-types';`
- used by going below the class definition
- `Person.propTypes = { click: PropTypes.func, name: PropTypes.string, age: PropTypes.number, changed: PropTypes.func  };`

以上是关于markdown 40 - 验证道具的主要内容,如果未能解决你的问题,请参考以下文章

markdown 38 - 传递未知的道具

markdown 04 - 使用道具

markdown 道具(子へのデータの渡し方)

道具验证中缺少反应/道具类型

在 React.js 中进行道具验证时道具类型失败

道具验证中缺少 React eslint 错误