use static defaultProps, for example:
export default class AddAddressComponent extends Component { static defaultProps = { provinceList: [], cityList: [] } 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: PropTypes.array.isRequired, }
Taken from: https://github.com/facebook/react-native/issues/1772
If you want to check types, see how to use PropTypes in treyhakanson or Ilan Hasanov, or see the many answers in the link above.
Brandon Keith Biggs Nov 12 '17 at 2:07 p.m. 2017-11-12 14:07
source share