October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Salesforce LWC Communication: Parent and Child Components Explained

Use @api properties to pass data down, public methods for parent-to-child commands, events for child-to-parent messages, and Lightning Message Service across DOM trees where supported.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Lightning Web Components (LWC), a parent passes data down through a child’s public @api properties, and a child reports actions or requested changes upward with DOM events. Use an @api method when the parent needs to command a child, and Lightning Message Service (LMS) when components do not share a DOM tree. Keep ownership of state with the component that owns it, and check that the Salesforce container supports LMS before relying on it.

How do parent and child components communicate in LWC?

Choose a communication method based on the relationship and direction of the message. Salesforce’s model is one-way: an owner supplies values to descendants; a child signals a requested change, and the owner decides whether to update its state. This avoids giving a child control over data it does not own. See Salesforce’s Data Flow guidance and Communicate with Events.

As an Amazon Associate I earn from qualifying purchases.

Situation Use Key constraint
Parent supplies configuration or data to a child Public @api property Child treats supplied objects and arrays as read-only.
Parent asks a child to perform an imperative action Public @api method Expose only the methods that belong in the child’s public API.
Child reports a selection, action, or requested change DOM event, usually CustomEvent Use the least propagation needed; keep the event payload public and clear.
Components do not share a DOM tree, or communication crosses technologies Lightning Message Service Verify support for the Salesforce experience and participants involved.

How do I pass data from a parent to a child in LWC?

Use a public property for data

Declare a field with @api in the child, then set it through the child element in the parent template. JavaScript property names use camel case; HTML attributes use kebab case. For example, the JavaScript field itemName is written as item-name in markup. Salesforce documents this pattern in Set Properties on Children and Decorators.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// child.js
import { LightningElement, api } from 'lwc';

export default class Child extends LightningElement {
  @api itemName;
}
<!-- parent.html -->
<c-child item-name="Example"></c-child>

This example shows the API shape; it is not a tested implementation. Prefer clear, specific inputs—especially primitive values—when practical, so a child’s accepted inputs are easy to understand.

Keep ownership of objects and arrays

A value passed from an owner is not an invitation for the child to mutate the owner’s state. Treat supplied objects and arrays as read-only. If the child needs to propose a change, it should emit an event and let the owner decide how to update its state. When making a local change to an object or array, work on a copy rather than changing the supplied reference. Salesforce explains this ownership model in Data Flow.

Use a public method for a command

When the parent needs a child to perform an imperative action—such as a player’s play() or pause() operation—expose a method with @api. The parent can call that method on the child element it owns. A public method is part of the component’s API, so make it deliberate rather than exposing internal implementation details. See Salesforce’s Call Methods on Children guide.

How does a child send data to its parent in LWC?

Dispatch a DOM event

A child commonly uses CustomEvent to report a user selection or propose a state change. Put the value the parent needs in detail; primitive payloads are usually the simplest contract. The parent can listen declaratively in its template and handle the event in its JavaScript class.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// child.js
this.dispatchEvent(new CustomEvent('select', {
  detail: this.selectedId
}));
<!-- parent.html -->
<c-child onselect={handleSelect}></c-child>

The event name and payload shape are a contract between child and parent. If the payload is an object or array, send a copy when the receiver should not be able to mutate the child’s internal state by reference. The parent receives the proposal; it remains responsible for deciding whether and how to change owner-controlled data. Salesforce’s Communicate with Events and Handle Events cover dispatch and handling.

Keep event propagation narrow

By default, bubbles and composed are both false. Start with that least-permissive scope and widen it only when the design requires it. Setting both to true lets an event bubble through ancestors and cross shadow boundaries, making it visible more broadly and turning it into a wider public contract. That can create name collisions and make components harder to evolve independently. See Salesforce’s Configure Event Propagation and Events Best Practices.

Shadow DOM also encapsulates a component’s internals: the event’s target can be retargeted outside the shadow boundary. Consumers should use the event’s public payload rather than reaching into child internals. Declarative template listeners are generally preferable. If a listener must be added imperatively, keep the same handler reference for removal; repeatedly calling .bind() creates new function instances and can prevent removal.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do sibling LWC components communicate?

If components are not in the same DOM tree, use Lightning Message Service rather than trying to turn an unrelated component into a parent-child relationship. Declare a Lightning message channel, then publish and subscribe through the message service. LMS can also connect LWC, Aura, and Visualforce participants in supported Salesforce experiences. Salesforce identifies it as the preferred approach for communication across the DOM: Communicate Across the DOM and Lightning Message Service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm support for the actual container before choosing LMS. Salesforce documents support in Lightning Experience standard and console navigation, Salesforce mobile for Aura and LWC (not Visualforce pages), and Aura- and LWR-based Experience Builder sites. Its limitations guidance says LMS does not work with Salesforce Tabs + Visualforce sites or Visualforce pages in Experience Builder sites. See Message Service Limitations.

The older pubsub utility is a fallback only for containers that do not support LMS. Salesforce describes it as page-limited, requiring manual unregistration, and no longer officially supported or actively maintained; it is not an equivalent first choice.

A quick rule for choosing

  • Data or configuration flowing from owner to child: public @api property.
  • Imperative command from parent to child: public @api method.
  • Selection, action, or proposed change flowing from child to owner: DOM event, with minimal propagation.
  • Communication between components outside the same DOM tree: LMS, after checking container support.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.