I have a parent component called "Component_A" and i have a child component "Component_B". I am trying to get data from server in the parent component and pass it down to child component as props. But my props will not have values in it before i make the ajax call in "componentDidMount" function in parent "Component_A". So i am trying to set defaultProps in child component "Component_B" using the "getDefaultProps". But looks like it doesnt work!
var Component_A = React.createClass({
componentDidMount : function(){
//Get data from server and set it in state variable called "data"
},
render : function(){
return (
<ComponentB sampleData={this.state.data} />
)
}
})
var ComponentB = React.createClass({
getDefaultProps : function (){
return {
data : {
vehicle : {
make :{
name : "Ford"
},
model : {
name : "Focus"
}
}
}
}
},
render : function(){
return (
<div> {this.props.data.vehicle.make.name} </div>
)
}
})
when i load the page, i get "Uncaught TypeError: Cannot read property 'make' of undefined"