Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram showing the structure and inheritance of custom and base Salesforce Aura components
Lightning

How to Extend Components in the Aura Framework (Salesforce) | Aura component inheritance

The short answer

Aura component inheritance allows developers to share markup, attributes, and methods from a base component to child components using the extends attribute. This technique standardizes user interface logic and eliminates duplicate code across components.

Key takeaways Add extensible="true" to the base component tag to permit child components to inherit from it. Assign access="public" to base attributes and methods so child components can access and execute them. Include {!v.body} in the base component markup to render child markup within the parent layout structure. Override base component controller logic by defining a function in the child controller with the matching name. Choose component composition over inheritance when wrapping UI elements to avoid rigid component dependencies.

Mastering Aura Component Inheritance in Your Projects

Even though LWC is the standard these days, many of us are still working in orgs where Aura component inheritance is a daily reality. I've seen teams struggle with massive, repetitive components simply because they didn't realize they could share logic between a base and a child. If you're tired of copy-pasting the same helper functions or UI patterns, learning how to extend components is going to save you a lot of headaches.

In my experience, the biggest win here isn't just saving lines of code. It's about consistency. When you use Aura component inheritance correctly, you can define a "source of truth" for how certain parts of your UI behave, and every child component just falls in line. But there are some specific rules you need to follow to keep things from breaking.

Understanding Aura Component Inheritance Basics

The core of this is the extends attribute. You add it to your <aura:component> tag in the child, pointing to the base component you want to copy. It's pretty straightforward, but here's the thing: you have to make sure your base attributes and methods are actually visible to the child.

  • The Extends Attribute: This is the link that tells Salesforce your component is a child of another.
  • Public Access: You must set access="public" on your attributes and methods. If they're private, the child can't see them, and you'll be left wondering why your code isn't working.
  • Method Sharing: Using <aura:method> allows the base component to expose a specific API that the child can trigger or even override.

One thing that trips people up is thinking that inheritance solves everything. It doesn't. While it's great for sharing a common look and feel, it can make your code harder to follow if you go too deep. I usually tell my team to keep it to one or two levels max.

A technical diagram showing a base component branching into two extended components to illustrate a simple inheritance hierarchy.

A technical diagram showing a base component branching into two extended components to illustrate a simple inheritance hierarchy.

A Real-World Example of Aura Component Inheritance

Let's look at a simple scenario. Imagine you have a base "Box" component that handles a title and a specific action. You want other components to use that same box but add their own flavor. This is a classic case for Aura component inheritance.

Here is what your base component (c:baseComponent) might look like:

<aura:component extensible="true">
    <aura:attribute name="title" type="String" access="public" default="Base Title" />
    <aura:method name="showTitle" action="{!c.showTitle}" access="public" />

    <div class="base-box">
        <h3>{!v.title}</h3>
        <lightning:button label="Show" onclick="{!c.handlePress}" />
    </div>
    {!v.body}
</aura:component>

And the controller for that base component:

({
    showTitle : function(component, event, helper) {
        var t = component.get("v.title");
        alert("Base title: " + t);
    },
    handlePress : function(component, event, helper) {
        component.showTitle();
    }
})

Building the Child Component

Now, when we create the child component, we use that extends attribute. This child will automatically get the title attribute and the showTitle method from the parent. You can even link to more advanced logic like the @AuraEnabled annotation if your base component needs to talk to Apex.

<aura:component extends="c:baseComponent">
    <aura:attribute name="subtitle" type="String" access="public" default="Child Subtitle" />

    <div class="child-box">
        <h4>{!v.subtitle}</h4>
    </div>
</aura:component>

The child can also have its own controller logic. If you name a function the same as one in the base controller, the child version is what gets called. This is how you override behavior. If you're prepping for a senior Salesforce developer interview, expect questions on this exact topic - they love to see if you understand the difference between overriding a method and extending it.

When to Use Composition Instead

Honestly, most teams get this wrong by trying to force inheritance for every shared piece of code. Aura component inheritance creates a tight link between the parent and child. If you change the parent, you might accidentally break ten different child components. That's not a fun day at the office.

Pro Tip: If you just need to wrap a component inside another to reuse a UI piece, use composition. Put the base component inside the new one as a child. Only use inheritance when the components truly share the same core DNA and logic.

Composition is usually more flexible because it lets you mix and match different behaviors without being stuck in a rigid hierarchy. If you find yourself writing "hacks" to get around parent logic, that's a huge red flag that you should be using composition instead.

Key Takeaways for Aura Component Inheritance

  • Always set extensible="true" on your base component or it won't work.
  • Use access="public" for any attributes you want the child to use.
  • Keep your inheritance chains short - one level is usually enough.
  • Remember that children inherit attributes and methods, but not private helper functions.
  • Use {!v.body} in the base component if you want child markup to show up inside the parent's layout.

Wrapping Up

Using Aura component inheritance is a powerful way to keep your Salesforce org clean, but it requires a bit of discipline. Start by identifying common UI patterns that truly share the same logic. Build a solid base, expose what you need through public methods, and keep the child components focused on their specific tasks. It makes your code easier to read and much easier to maintain over time. Just don't over-engineer it - simple is almost always better in the long run.

Frequently asked questions

How do you extend a base component in the Aura framework?

Add the extends attribute to the child component's <aura:component> tag pointing to the base component name, and ensure the base component specifies extensible="true".

How do you override controller methods in child Aura components?

Define a controller function in the child component that uses the exact same name as the base controller function. The child version will automatically execute in place of the base version.

When should you use composition instead of inheritance in Aura?

Use composition when you need to wrap or reuse a UI element without tightly coupling logic across components. Inheritance should be reserved for components that share core behavior and DNA.

What is the purpose of {!v.body} in an extensible base component?

Including {!v.body} in the base component allows any markup declared in an extending child component to render inside the parent component's layout.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment