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.

Related concepts

Declaring Default Props

React Without ES6: Declaring Default Props — Structure map

Clickable & Draggable!

React Without ES6: Declaring Default Props — Related pages: