Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 PointsHow do we know what we've made is a component class?
And what other types of class are there? Are they all covered by the createClass method? How does it work?
var Counter = React.createClass({
render: function() {
return ();
}
});
2 Answers
Seth Kroger
56,413 PointsThe createClass method is a helper that creates an object that extends React.Component. That object will be the prototype for any instances of you custom component, which is as close to a class as you'll get in JavaScript. We know it's a Component class because that is what createClass() will specifially create. It's use is mainly for people not using ES6: https://facebook.github.io/react/docs/react-without-es6.html
If you are coding with ES6 (with or without Babel) you would be using the new class syntax instead.
import React, {Component} from 'react';
class Counter extends Component {
render() {
// etc...
}
}
Iain Simmons
Treehouse Moderator 32,305 PointsI think Jim was also trying to distinguish between component classes and component functions (i.e. the stateless/dumb components).