What Is Components in React?
->In React, components are the building blocks of a React application. They allow developers to break the UI into independent, reusable pieces.
React components can be broadly categorized into two types Those are:
1.Functional Components
2.Class Components
Let us know these components in details->
**
1.Functional Components:
**
Definition: JavaScript functions that return React elements (JSX).
Purpose: Used for simpler components that primarily render UI.
-
Characteristics:
- Stateless (before React Hooks were introduced).
- Can use React Hooks (like useState and useEffect) to manage state and lifecycle in modern React
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
.
2. Class Components
- Definition: ES6 classes that extend the React.Component class.
Purpose: Used when state management or lifecycle methods are needed.
Characteristics
Stateful and Becoming less common with the advent of Hooks.
Includes lifecycle methods like componentDidMount, shouldComponentUpdate, etc.
class Greeting extends React.Component {
render() {
return <h1>Hello, {this.props.name}!</h1>;
}
}
Thank You Keep Learning React
Top comments (0)