In Lightning Web Components (LWC), components communicate up the containment hierarchy (from child to parent) by creating and dispatching Custom Events.
Unlike the older Aura framework, which used specific "Component" or "Application" event types (Options B and C), LWC relies on standard web browser event protocols. The child component (c-order) would instantiate a CustomEvent object, optionally including a data payload in the detail property (such as the orderId), and then call the this.dispatchEvent() method.
The parent component (c-selected-order) then listens for this event using an on prefix (e.g., onselection={handleSelection}) in its HTML template. While you could technically use a standard DOM event (Option D), the CustomEvent interface is the platform-standard best practice in LWC for passing custom data payloads between components. Custom events allow for clean encapsulation and follow the modern "Events Up, Properties Down" design pattern common in reactive frameworks like LWC, React, and Vue.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit