Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
ReactJS Components Complete Reference
Next article icon

ReactJS Components Complete Reference

Last Updated : 24 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In ReactJS, components are the building blocks that help you create interactive UIs by dividing your app into smaller, reusable pieces of code. Understanding how components work is essential for efficiently developing React applications.

In this article will provide a complete reference to React components, covering their types, usage, and key differences between class and functional components.

What are ReactJS Components?

Components in React are JavaScript functions or classes that return a piece of UI. These components allow developers to build complex UIs from small, isolated, and reusable pieces. React components are the core building blocks for any React application and can manage their state, handle user inputs, and render dynamic content.

Types of React Components

There are two main types of components in React:

  • Functional Components
  • Class Components

Functional Components

A Functional Component is a simpler and more concise way of writing components in React using JavaScript functions. These components receive props (properties) as an argument and return JSX (JavaScript XML) to define the UI structure.

JavaScript
import React, { useState } from 'react';  const Welcome = () => {      const [message, setMessage] = useState("Hello, World!");      return (         <div>             <h1>{message}</h1>             <button onClick={() => setMessage("Hello, React!")}>                 Change Message             </button>         </div>     ); };  export default Welcome; 

Output

functional-component
Functional Components

 In this code

  • useState is used to manage the message state, initially set to "Hello, World!".
  • The button click triggers setMessage, which updates the message state to "Hello, React!".
  • The component displays the message in an <h1> element and updates it when the button is clicked.

Class Components

Class components in React are ES6 classes that extend the React.Component class. They are used for creating components that need to have their own state or lifecycle methods. While functional components are now the go-to choice for many developers (especially with the introduction of hooks like useState and useEffect), class components still have their place and provide a more traditional way of handling component logic in React.

JavaScript
import React, { Component } from 'react';  class Counter extends Component {     constructor(props) {         super(props);          this.state = {             count: 0         };     }      increment = () => {         this.setState({ count: this.state.count + 1 });     };      decrement = () => {         this.setState({ count: this.state.count - 1 });     };      render() {         return (             <div>                 <h1>Counter: {this.state.count}</h1>                 <button onClick={this.increment}>Increment</button>                 <button onClick={this.decrement}>Decrement</button>             </div>         );     } }  export default Counter; 

Output

class-component
Class Components in React

In this code

  • state: The counter (count) is initialized to 0 in the constructor.
  • increment and decrement: These methods update the count state by 1 when the respective buttons are clicked.
  • render: Displays the current count and two buttons to increment or decrement the counter.

Difference between Class component and Functional component

Feature

Functional Components

Class Components

Definition

A function that returns JSX.

A class that extends React.Component and has a render() method.

State

Can use state via hooks like useState.

Can manage state using this.state and this.setState().

Lifecycle Methods

No lifecycle methods (use useEffect hook).

Uses lifecycle methods like componentDidMount, componentDidUpdate, componentWillUnmount.

Syntax

Simpler syntax, function-based.

More verbose, class-based syntax.

Performance

More lightweight and performant.

Slightly heavier due to the class structure and additional methods.

Use of Hooks

Can use hooks like useState, useEffect, etc.

Cannot use hooks directly.

Rendering

Directly returns JSX.

Must define a render() method to return JSX.

Context

Easier to integrate with React hooks like useContext.

Uses Context.Consumer for context integration.

Complete Reference

  • React Components
  • React Components – Set 2
  • React Pure Components
  • React Functional Components
  • React Class Components
  • React Component Based Architecture
  • Controlled vs Uncontrolled Components
  • ReactComponent Composition
  • Lifecycle of React Components
  • Functional vs Class Components
  • Presentational vs container components

Next Article
ReactJS Components Complete Reference

K

kartik
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • ReactJS-Component

Similar Reads

    React Desktop macOS Component Complete Reference
    React Desktop is a popular JavaScript library that is built on top of Facebook's React library, which focuses to bring the native desktop experience to the web. We can utilize the react-desktop in any of the Javascript projects that work perfectly along with supporting the NW.js & Electron.js. T
    1 min read
    ReactJS UI Ant Design Other Component Complete Reference
    Ant Design is a popular ReactJS UI library that is used to build the design system for enterprise-level products. The Ant Design contains a rich set of high-quality components for building efficient & interactive user interfaces with an enjoyable work experience. Ant design facilitates a huge nu
    1 min read
    ReactJS UI Ant Design Layout Component Complete Reference
    Ant Design is a popular ReactJS UI library that is used to build the design system for enterprise-level products. The Ant Design contains a rich set of high-quality components for building efficient & interactive user interfaces with an enjoyable work experience. Ant design facilitates a huge nu
    1 min read
    React Desktop Windows 10 Component Complete Reference
    React Desktop is a popular JavaScript library that is built on top of Facebook's React library, which focuses to bring the native desktop experience to the web. We can utilize the react-desktop in any of the Javascript projects that work perfectly along with supporting the NW.js & Electron.js. T
    1 min read
    ReactJS UI Ant Design General Component Complete Reference
    Ant Design is a popular ReactJS UI library that is used to build the design system for enterprise-level products. The Ant Design contains a rich set of high-quality components for building efficient & interactive user interfaces with an enjoyable work experience. Ant design facilitates a huge nu
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences