Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
const needDefaultValue = false;
React.createElement('input', needDefaultValue ? { defaultValue: i } : {});
// или
const params = {};
if(needDefaultValue) params.defaultValue = i;
<input {...params} />;
The question is a little unclear. If you want to set the default value of the prop, then it is done like this
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.defaultProps = {
cityList: [],
provinceList: [],
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question