如何在React组件上设置组件默认道具

如何在React组件上设置组件默认道具,第1张

如何在React组件上设置组件默认道具

您忘记合上

Class
支架了。

class AddAddressComponent extends React.Component {  render() {    let {provinceList,cityList} = this.props    if(cityList === undefined || provinceList === undefined){      console.log('undefined props')    } else {      console.log('defined props')    }    return (      <div>rendered</div>    )  }}AddAddressComponent.contextTypes = {  router: React.PropTypes.object.isRequired};AddAddressComponent.defaultProps = {  cityList: [],  provinceList: [],};AddAddressComponent.propTypes = {  userInfo: React.PropTypes.object,  cityList: React.PropTypes.array.isRequired,  provinceList: React.PropTypes.array.isRequired,}ReactDOM.render(  <AddAddressComponent />,  document.getElementById('app'))<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script><div id="app" />


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5662486.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存