mangocaptain
mangocaptain

Reputation: 1495

React createClass specification object formatting

Probably an elementary question, but why is it in React, when you use createClass it can take an specification object in a format that is a key-value pair, such as

React.createClass({
   render: function () {...},
   componentDidMount: function () {...}
})

vs. a function declaration?

React.createClass({
   render () {...},
   componentDidMount () {...}
})

How can they both work? Does react magically change the declarations into an object key value pair for you?

Upvotes: 1

Views: 46

Answers (1)

goldbullet
goldbullet

Reputation: 702

They are the same. One is Method Definitions from ES2015 and the other is the traditional way. So, no React doesn't do anything but it's just how JavaScript works now. (As long as the browser supports it or a preprocessor like Babel converts it to ES5)

Upvotes: 2

Related Questions