freeCodeCamp/guide/chinese/certifications/front-end-libraries/react/review-using-props-with-sta.../index.md

739 B
Raw Blame History

title localeTitle
Review Using Props with Stateless Functional Components 查看使用无状态功能组件的道具

查看使用无状态功能组件的道具

提示

  • 功能又名无状态组件只是一个简单的javascript函数它将props作为参数并返回一个react元素。
  • 使用Component.defaultProps设置默认道具。
  • 使用Component.propTypes设置道具类型。

const Camper = props => (<p>{props.name}</p>); 
 
 Camper.defaultProps = { 
  name: 'CamperBot' 
 }; 
 
 Camper.propTypes = { 
  name: PropTypes.string.isRequired 
 }; 

相关链接