Dhaval
Dhaval

Reputation: 389

What does mean by "Two components of the same class will generate similar trees" in ReactJS

I have read it in Reactjs documentation that "Two components of the same class will generate similar trees and two components of different classes will generate different trees." but did not understood what does it mean.

Upvotes: 1

Views: 162

Answers (1)

Kyeotic
Kyeotic

Reputation: 19847

Components in this context refers to a React Component, which is JavaScript/JSX object that has a render function that returns a DOM node. DOM Nodes are trees, in that they can contain children DOM Nodes. These are the Trees being referenced.

Components are defined as classes, either using ES6 class syntax, or using React.createClass. So what that is saying is that two Component instances of the same type will produce similar DOM Node trees (the two Components will have similar structure, because they contain the same rendering logic). This is not guaranteed though, as the render function could contain logic that produces completely different results.

Two component instances of different types may have very different DOM node trees, since they probably don't use the same render function.

Upvotes: 1

Related Questions