Reputation: 359
I'm very new to this, so please bear with me everyone. I have studied React where a component is created like,
var app = React.createClass({ ... });
Just like here.
However, after installing react in my mac, I see that the syntax is a bit different from what I'm used to. i.e.,
class Application extends React.Component { ... }
Just like here.
Now, I did understand the code due my prior knowledge in Java. But I just wanted to know the difference. This is proving to be a problem for me because when I wrote the syntax like React.createClass(), it didn't work.
If you look at the second link in codepen you'll see that Babel is written beside JS. So, does react use Babel by default?
I think you get the picture. Thanks!
Upvotes: 2
Views: 207
Reputation: 42460
Your first example uses the React.createClass()
helper function, while the second one uses the ES6 class syntax to define a React component.
Both are valid approaches to defining components. Note however, that you will need to transpile your ES6 code to ES5 before shipping it to make it cross-browser-compatible.
More info on ES6-style component definitions.
Upvotes: 2