The title might not be the best way to describe the problem, but I was wondering if there was a better practice to declaring an object in getDefaultProps
?
In my render
method I call several keys from from a prop/state that get updated on a click event i.e. this.props.player.name
. The problem is that on page load this.props.player
is blank and calling .name
errors out. I know I can do something like ...
getDefaultProps: function() {
return {
player: {
name: null,
team: null
position: null
}
};
}
but it doesn't feel right. I was hoping there might be something similar to how Ruby does .try()
where it won't try to call a method on a undefined prop.