You get a bonus - 1 coin for daily activity. Now you have 1 coin

What is the difference between an element and a component? in REACT

Practice



An element is a plain object , describing what , you want , to appear on the screen in terms of DOM nodes or other components. Elements can contain other elements in their props. Creating a React element is cheap. Once an element is created, it is never mutated.

The object representation of a React element looks like this:

const element = React.createElement(
  'div',
  {id: 'login-btn'},
  'Login'
)

The above

React.createElement()
function returns an object:
 
 
 
 
{ type: 'div', props: { children: 'Login', id: 'login-btn' } }

 
 

And finally, it is rendered to the DOM using

ReactDOM.render()
:
<div id='login-btn'>Login</div>
 

Whereas a component can be declared in several different ways. It can be a class with a

render()
method. Alternatively, in simple cases it can be defined as a function. In either case it takes props as input and returns a JSX tree as output:
const Button = ({ onLogin }) =>
  <div id={'login-btn'} onClick={onLogin}>Login</div>

The JSX is then transpiled into a

React.createElement()
function tree:
const Button = ({ onLogin }) => React.createElement(
  'div',
  { id: 'login-btn', onClick: onLogin },
  'Login'
)
created: 2020-02-23
updated: 2026-03-09
405



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone