9
如何在React组件上设置组件默认道具
我使用下面的代码在React组件上设置默认道具,但它不起作用。在该render()方法中,我可以看到输出“ undefined props”已打印在浏览器控制台上。如何定义组件道具的默认值? export default class AddAddressComponent extends Component { render() { let {provinceList,cityList} = this.props if(cityList === undefined || provinceList === undefined){ console.log('undefined props') } ... } AddAddressComponent.contextTypes = { router: React.PropTypes.object.isRequired } AddAddressComponent.defaultProps = { cityList: [], provinceList: [], } AddAddressComponent.propTypes = { userInfo: React.PropTypes.object, cityList: PropTypes.array.isRequired, provinceList: …
134
reactjs
ecmascript-6