I have a track
prop with the following definition:
propTypes: {
track: React.PropTypes.shape({
cover: React.PropTypes.string,
getDefaultProps
does not merge passed property values with the return value specified. If the property does not exist, React will use the object returned by getDefaultProps
to initialize the component instance.
The code below for example produces:
Test Cover and
Code:
var TrackItem = React.createClass({
render: function() {
var track = this.props.track;
return ({track.cover} and {track.artist});
},
getDefaultProps: function() {
return {
track: {
artist: 'def artist'
}
}
}
});
var track = {
cover: 'Test Cover'
};
React.render( , mountNode);
Also, note that objects returned in getDefaultProps
are shared across all instances of a component (reference).