React Js / Basics / React Elements vs components
React Elements vs Components
-
Note
React Element
An Element is an object that represents a DOM node it is a part of DOM structure
React Element does not have any methods, making it light and faster to render than components.
React ComponentIt is independent and reusable. It returns the virtual DOM of the element. It contains elements and encapsulate logic, structure, and behavior for parts of your UI.
Difference between Element and Component
Element Component The element does not have any methods. Each component has its methods. A React element is an object representation of a DOM node. A component encapsulates a DOM tree. Elements are immutable i,e once created cannot be changed. The state in a component is mutable. How to create element and components
Elementcreate element
const myHeading = Welcome to my React app!
;Rendering the element to the DOM:
ComponenetReactDOM.render(myHeading, document.getElementById('root')); create component
// Functional component: function WelcomeMessage(props) { return Hello, {props.name}!
; } // Class component: class Greeting extends React.Component { render() { returnGreetings, {this.props.user}!
; } }usage and rendering
// Using the components: ReactDOM.render( , document.getElementById('root') );
MANVIA BLOG