PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

React · Theory

Composition vs Inheritance in React

← All stacks

Theory

69/94

Composition vs Inheritance in React

React’s docs say: use composition, not inheritance, for UI. Pass children, render props, or small wrapper components. <Card><h2>Shoes</h2></Card> instead of class SaleCard extends Card. You reuse Card’s shell without a class tree.

Inheritance still exists in JS, but UI ‘is-a’ chains get brittle. Share logic with hooks, share layout with children.

Composition vs Inheritance in React — on screen: Shoes + 20% off inside Card. children is the composition knob.

Exam tip

children example vs extends.

Example

// Composition
function Card({ children }) {
  return <article className="card">{children}</article>;
}

export default function Sale() {
  return (
    <Card>
      <h2>Shoes</h2>
      <p>20% off</p>
    </Card>
  );
}

Composition vs Inheritance in React — on screen: Shoes + 20% off inside Card. children is the composition knob.

Short notes

  • DefPrefer : children / wrappers / hooks.
  • RuleAvoid : SaleCard extends Card.
  • RememberWhy : brittle UI trees.

Questions

1

How do you compare Composition vs Inheritance on the board? One real difference, one shared idea.

2

What naming trap should you avoid?

3

When would you still pick the other side?

Previous← Dropdown in ReactNextComments in React →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.