stackjlei
stackjlei

Reputation: 10035

What is React's createClass's parameter look like exactly? Is it an object?

I feel like I've seen both versions of React's creatClass, with the former being more apparent in the docs. Is there any differences between the 2 other than the stylistic ones? Just seems weird that the first style looks like it's accepting an object, whereas the second is just a scope with any functions you want to throw at it.

var Greeting = React.createClass({
  someFunction: function () {
    ...
  },

  getDefaultProps: function() {
    return {
      name: 'Mary'
    };
  },

  // ...

});

vs.

var Greeting = React.createClass({
  someFunction () {
    ...
  }

  getDefaultProps () {
    return {
      name: 'Mary'
    };
  }

  // ...

});

Upvotes: 1

Views: 44

Answers (1)

Pranesh Ravi
Pranesh Ravi

Reputation: 19113

This is not with react. It is a ES6 feature called Object Literals

const a = 10;

const b = {
  a, //which is equal to a: a 
}

function a(){}

const c = {
  a, //which is equal to a: function a(){}
}

Upvotes: 2

Related Questions