What is Components Inheritance in React ? Last Updated : 17 Nov, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In React, Component Inheritance refers to one component inheriting the behaviors of another component. It allows objects to have those properties that already exist on previous or parent objects. It is a concept that plays a major role in object-oriented programming. Two classes exist for Component Inheritance in React are: Superclass(Parent Class Component)Subclass(Child Class Component)In React, the composition model is used instead of inheritance, so that code can be re-used again between the components. In react extends keyword is used on the main function i.e. the constructor function. By using the extends keyword you can have the present component have all the component properties from the already existing component. The composition model uses the super-sub-class relationship by passing the state and props. The sub-class segment can access any progressions to one another. Steps to Create React Application:Step 1: Create a React application using the following command in the terminal/ command prompt: create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command: cd foldernameProject Structure: Project StructureExample: This example implements component inheritance by rendering a message in the ChildComponent passed from the Parent component. JavaScript // Filename - App.js import React from "react"; import "./App.css"; import ChildComponent from "./ChildComponent"; class App extends React.Component { constructor(props) { super(props); this.state = { message: " Geeks for Geeks message", }; } render() { return ( <div> <ChildComponent message={this.state.message} /> </div> ); } } export default App; JavaScript // Filename - ChildComponent.js import React from "react"; class ChildComponent extends React.Component { render() { const { message } = this.props; return ( <div> <p> {" "} Message from App component :{" "} <b>{message}</b>{" "} </p> </div> ); } } export default ChildComponent; Step to Run Application: Run the application using the following command from the root directory of the project: npm startOutput: This output will be visible on the http://localhost:3000/ on the browser window. Child Component accessed App component properties Comment More infoAdvertise with us Next Article What are Class Components in React? S sharmasakshi0811 Follow Improve Article Tags : Web Technologies ReactJS React-Questions Similar Reads React Native Smart Components In this article, we are going to learn about Smart components in React Native. The smart component is one of the categories of React Components so before diving into the smart components detail. A Component is one of the core building blocks of React and React-Native. The component is a block of cod 3 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 Limitations of Class Components in React Class Components in React are like the older, more formal way of building things. They involve more code and can be a bit complex compared to the newer, simpler functional components. Think of them as the traditional way of doing things in React.Limitations of Class Components in React1. Confusing ' 4 min read Dumb Components in React Native In this article, we are going to learn about Dumb components in React Native. The dumb component is one of the categories of React Components, so before diving into the dumb component details. Let's know a little bit about components. A Component is one of the core building blocks of React. The comp 5 min read 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 Top React Components Interview Questions & Answers React Component is the building blocks of the React application. It is the core concept that everyone must know while working on React. In this tutorial, we will see the top React Components questions that can be asked in the interview. Letâs discuss some common questions that you should prepare for 15 min read Like