0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your explanation. It seems like a class vs object in c++.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.