Intermediate 18 min read

Parent-to-Child Communication with @api

By the end of this lesson, you'll be able to:

  • Use @api to expose a property a parent can set
  • Pass complex data — not just strings — down to a child component
  • Explain how the immutable update pattern keeps parent-to-child data flowing correctly

Prerequisites: Module 4: "Immutability and JavaScript Events"

Beyond the Basics

Module 3 introduced @api for a simple string property. @api can expose two kinds of things on a child component: properties (passive data, this lesson) and methods (imperative actions, Lesson 2).

// contactCard.js
import { LightningElement, api } from 'lwc';

export default class ContactCard extends LightningElement {
    @api contact;
}

Passing Complex Data

@api properties aren't limited to strings — an entire object or array can be passed down:

<!-- parent's template -->
<c-contact-card contact={selectedContact}></c-contact-card>
// contactCard.js
@api contact; // receives the full object: { Id, Name, Email, ... }
<!-- contactCard.html -->
<p>{contact.Name}</p>
<p>{contact.Email}</p>

Reactivity Across the Boundary

When the parent reassigns the object it's passing down — using the immutable update pattern from Module 4 — the child's @api property updates, and the child's template re-renders correctly:

// In the parent, after an edit:
this.selectedContact = { ...this.selectedContact, Email: newEmail };

Because this creates a new object reference rather than mutating the old one, the child genuinely receives a fresh value and re-renders — exactly the same reactivity principle from Module 4, now spanning a parent/child boundary.

Why This Matters in Real Projects

Almost every real LWC application is a tree of components passing data downward this way — a list component passing individual records to row components, a form passing field values to input sub-components, and so on.

Exercise

Declare an @api property named account on a child component, intended to receive a full Account record object from its parent.

Show hint

Import api from lwc first.

JAVASCRIPT

Exercise

Challenge: a parent mutates a field directly with this.selectedContact.Email = newEmail; and the child does not re-render. Explain why, and fix it.

Show hint

Recall Module 4's immutability lesson.

JAVASCRIPT

Parent-to-Child Communication with @api Quiz

1. What decorator exposes a property that a parent component can set?

2. Can an @api property receive a full object, not just a string?

3. Directly mutating a field on an object without reassigning it reliably updates a child's @api property.

4. What does @api expose besides properties?

5. What keeps a parent-to-child data update flowing correctly across the component boundary?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

The full depth on parent-to-child communication — passing complex objects and arrays down through @api, and how immutable updates (Module 4) keep that data flowing correctly.