Files
2018-10-16 21:32:40 +05:30

29 lines
739 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Review Using Props with Stateless Functional Components
localeTitle: 查看使用无状态功能组件的道具
---
## 查看使用无状态功能组件的道具
### 提示
* 功能又名无状态组件只是一个简单的javascript函数它将props作为参数并返回一个react元素。
* 使用`Component.defaultProps`设置默认道具。
* 使用`Component.propTypes`设置道具类型。
### 解
```javascript
const Camper = props => (<p>{props.name}</p>);
Camper.defaultProps = {
name: 'CamperBot'
};
Camper.propTypes = {
name: PropTypes.string.isRequired
};
```
### 相关链接
* [使用PropTypes进行类型检查](https://reactjs.org/docs/typechecking-with-proptypes.html)