React Without ES6: Declaring Default Props
Declaring Default Props
//with ES6
class Greeting extends React.Component {
// ...
}
Greeting.defaultProps = {
name: 'Mary'
};
//without ES6
var Greeting = createReactClass({
getDefaultProps: function() {
return {
name: 'Mary'
};
},
// ...
}); With functions and ES6 classes defaultProps is defined as a property on the component itself. With createReactClass(), you need to define getDefaultProps() as a function on the passed object.
Semantic portal