
Components in ReactJS
In ReactJS, components are the building blocks of a React application. They allow you to split the UI into independent, reusable pieces and think about each piece in isolation.
✅ Types of Components in React
There are two main types of components in React:
Functional Components
Class Components
📌 1. Functional Components (Recommended)
Functional components are simple JavaScript functions that return JSX (React's syntax extension for HTML). They are mainly used with Hooks for state and lifecycle management.
Example: Functional Component
<h1>Welcome, {this.state.name}!<div> <h1>Hello, {props.name}!<Greeting name="Vikash" />
props.name
→ DisplaysVikash
.Props are read-only and cannot be modified inside the child component.
✅ State in Components
In functional components: Use
useState
.In class components: Use
this.state
andthis.setState
.