KWANG KIM
KWANG KIM

Reputation: 1

Difference between ReactClass and ReactComponent?

In the React Dom Terminology, what is the difference between ReactClass and ReactComponent?

Upvotes: 0

Views: 1413

Answers (2)

Andre Pena
Andre Pena

Reputation: 59336

Simply put:

ReactClass: A model or a shape for components, if you want to create a component called DatePicker, the shape is the ReactClass, not each of the individual components/instances will you create based on that shape.

var MyComponent = React.createClass({
 render: function() {
    ...
  }
});

ReactComponent or ReactElement: A component instance that you create based on a pre-defined ReactClass. If you create a component called DatePicker, each instance of that component that is rendered is a ReactElement

var component = React.createElement(MyComponent, props);

Normally you don't use React.createElement because you can just use something like this <MyComponent />, but it's really useful if you want to dynamically create instances of components, like for storing in a variable and rendering them later.

Upvotes: 1

KWANG KIM
KWANG KIM

Reputation: 1

I just found it from my link. I keep this question for someone who may have the same question. From React Components,

A ReactComponent Class is simply just a JavaScript class (or "constructor function").

var MyComponent = React.createClass({
 render: function() {
    ...
  }
});

When this constructor is invoked it is expected to return an object with at least a render method on it. This object is referred to as a ReactComponent.

var component = new MyComponent(props); // never do this

Upvotes: 0

Related Questions