React · Frontend system thinking

Why does React prefer composition over inheritance?

EasycompositionchildrenreuseUpdated Oct 2026
Quiz this track

Short answer

Composition builds components from other components by passing children or render functions. It is more flexible than inheritance and avoids tight coupling between parent and child implementations.

React components are functions, not class hierarchies. Instead of extending a base component, you pass content into a generic container or extract shared behaviour into a hook.

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

function Profile() {
  return (
    <Card>
      <Avatar />
      <h2>Asha</h2>
    </Card>
  );
}

Other composition patterns

  • children for layout and container components
  • Render props for passing rendering logic into a component
  • Higher-order components for wrapping behaviour
  • Custom hooks for sharing stateful logic without changing the component tree

Inheritance couples a child to a parent's implementation and makes it hard to combine behaviours from multiple sources. Composition lets each component stay focused and lets the caller decide what to render.

You can still use class inheritance for error boundaries or third-party APIs, but it is not the default reuse mechanism in React.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the `children` prop?
  2. 2What is a render prop?
  3. 3How do custom hooks compare with higher-order components?
  4. 4When is inheritance still used in React?

Say it in the interview

React prefers composition because components are just functions. I can pass children or render functions into a generic container, or extract shared logic into a hook. That is more flexible than extending a base class, which couples the child to the parent implementation. Inheritance still appears in error boundaries and some libraries, but composition is the default reuse pattern.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.