DEV Community

Vishwas Bhat
Vishwas Bhat

Posted on

React Components:


Enter fullscreen mode Exit fullscreen mode

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:

    1. Stateless (before React Hooks were introduced).
    2. 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>;
}

Enter fullscreen mode Exit fullscreen mode

.

2. Class Components

  • Definition: ES6 classes that extend the React.Component class.
  • Purpose: Used when state management or lifecycle methods are needed.

  • Characteristics

  1. Stateful and Becoming less common with the advent of Hooks.

  2. Includes lifecycle methods like componentDidMount, shouldComponentUpdate, etc.

class Greeting extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}!</h1>;
  }
}

Enter fullscreen mode Exit fullscreen mode

Thank You Keep Learning React

Top comments (0)