I am trying to set defaultProp with an object literal, but after a while I realized that the constructor of the React class does not combine the default details with the attached details, so I get undefined values for any properties in the defaultProps literature that were not included in the application details. Is there a way to combine the default details and application details, or do I need to split my object into several details?
class Test extends React.Component {
constructor(props) {
super(props);
//props.test is only {one: false}
//props.test.two is undefined
}
render() {
return (<div>render</div>)
}
}
Test.defaultProps = {
test: {
one: true,
two: true
}
}
ReactDOM.render(<Test test={{'one': false}}/>, document.getElementById('#test'));
http://codepen.io/adjavaherian/pen/oYNPLz
source
share