How to create Class Component in React? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report JavaScript syntax extension permits HTML-like code within JavaScript files, commonly used in React for defining component structure. It simplifies DOM element manipulation by closely resembling HTML syntax. JSX facilitates the creation of reusable UI building blocks, defined as JavaScript functions or classes in React. Prerequisites:Node or NPMReactJSXSteps to Create React Application And Installing Module:Step 1: Create a React application using the following command: npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command: cd foldernameStep 3: After setting up React environment on your system, we can start by creating an App.js file and create a directory by the name of components in which we will write our desired function. Project Structure: The updated dependencies in package.json file will look like. "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4",}Example 1: In this example, we will demonstrate how to add a class component in our application. JavaScript //App.js import GeeksforGeeks from "./components/geeksforgeeks"; import "./styles.css"; export default function App() { return ( <div className="App"> { /* Creating custom JSX tag to return the component */ } <GeeksforGeeks /> </div> ); } JavaScript //GeeksforGeeks.js import React from "react"; /* This is the class component that will be added to the application */ class GeeksforGeeks extends React.Component { render() { return ( <div> <h2>GeeksforGeeks</h2> <p> A computer science portal for GeeksforGeeks </p> </div> ); } } export default GeeksforGeeks; Step to run the app: npm startOutput: Example 2: In this example, we will demonstrate how to add a class component in our application with a custom input by changing the contents of the header in the App.js file. JavaScript //App.js import GeeksforGeeks from "./components/geeksforgeeks"; import "./styles.css"; export default function App() { return ( <div className="App"> { /* Creating custom JSX tags with different inputs */ } <GeeksforGeeks data="GeeksforGeeks" /> <GeeksforGeeks data="A computer science portal" /> <GeeksforGeeks data="for geeks" /> </div> ); } JavaScript //GeeksforGeeks.js import React from "react"; /* This is the class component that will be added to the application with custom inputs */ class GeeksforGeeks extends React.Component { render() { return ( <div> <p>{this.props.data}</p> </div> ); } } export default GeeksforGeeks; Step to run the app: npm startOutput: Comment More infoAdvertise with us Next Article How to create Class Component in React? R rajatsandhu2001 Follow Improve Article Tags : Web Technologies ReactJS Geeks Premier League React-Questions Geeks Premier League 2023 +1 More Similar Reads How to create components in ReactJS ? Components in React JS is are the core of building React applications. Components are the building blocks that contains UI elements and logic, making the development process easier and reusable. In this article we will see how we can create components in React JS. Table of Content React Functional C 3 min read How to create a Functional Component in React? To create a functional component in React, you define a JavaScript function that returns JSX. These components are stateless and rely on props for data input. Functional components are concise, easy to read, and can utilize React Hooks for managing state and side effects, making them a fundamental b 2 min read How to create Functional Components in React ? To create a functional component in React, you define a JavaScript function that returns JSX. These components are stateless and rely on props for data input. Functional components are concise, easy to read, and can utilize React Hooks for managing state and side effects, making them a fundamental b 2 min read How to create Menu Item Component in ReactJS ? React JS is a popular JavaScript library used for building user interfaces. It provides a component-based architecture that allows developers to create reusable UI elements. Material UI for React has this component available for us and it is very easy to integrate. We can use Menu Component in React 2 min read What are Class Components in React? Class components in React are fundamental building blocks for creating reusable, stateful, and interactive user interfaces. Unlike functional components, class components can manage their own state and lifecycle methods, making them a preferred choice for more complex applications before the introdu 3 min read How to use Badge Component in ReactJS? Badge generates a small badge to the top-right of its children component. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Badge Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReact JSMaterial UISteps to Create 2 min read How to convert functional component to class component in ReactJS ? ReactJS offers two primary ways of creating components: functional components and class components. While functional components are more concise and easier to reason about, there are situations where class components may be necessary with the flexibility to use lifecycle methods and manage the state 2 min read React Class Components Class components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el 4 min read How to add Stateful component without constructor class in React? Generally, we set the initial state of the component inside the constructor class and change the state using the setState method. In React basically, we write HTML-looking code called JSX. JSX is not a valid JavaScript code but to make the developer's life easier BABEL takes all the responsibility t 2 min read ReactJS Reactstrap Card Component Reactstrap: Reactstrap is a popular front-end library that is easy to use React Bootstrap 4 components. This library contains the stateless React components for Bootstrap 4. The Card components allow the user to display content. We can use the following approach in ReactJS to use the ReactJS Reactst 5 min read Like