What is the difference between element and component ?

 

 Element

 

Component

It is an object describing what you would like to project on the screen in terms of the DOM nodes or other components. It is a function or class that accepts an input and returns a React element.
 

It contains other elements in its props.

 

It can be a class with a render() method.

 

It describes what we want to see on the screen

 

It is a template. A blueprint. A global definition.

 

It is an immutable description object and you can not apply any methods on it

 

It has to keep references to its DOM nodes and to the instances of the child components.

 

There is no any method used.

 

The lifecycle method is used for each element.

 

They are immutable i,e once created cannot be changed.

 

The state in a component is mutable.

 

React Hooks cannot be used with elements as elements are immutable.

 

React hooks can be used with both functional and class components

 

Elements are faster.

 

Components are slower.

 

It is an object representation of a DOM node.

 

It is an object representation of the DOM tree.

 

 

e.g,
<button class=”white”> </button>

 

e.g,

const LogIn = () => (

<div>

<p> Login </p>

<button> Continue </button>

<button color = “orange”> Cancel </button>

</div>

);

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

What is Prop Drilling ?

We pass a prop with another component with the help of all the components that come between, this method is known as prop drilling. Prop drilling is basically a situation…
View Answer

What is React DOM ?

It is an object which exposes a number of top level APIs to interact with the browser DOM. It provides DOM-specific methods that can be used at the top level…
View Answer

What is Flux ?

It is an application architecture that Facebook makes use of internally for constructing the client-side web application with React . It is a programming concept, where the data is a…
View Answer