PDI · Question #200
Which two characteristics are true for Lightning Web Component custom events? Choose 2 answers
The correct answer is B. By default a custom event only propagates to its immediate container and to its immediate child D. Data may be passed in the payload of a custom event using a property called detail. Lightning Web Component custom events can pass data using the detail property, and when configured to propagate, their scope is typically limited to bubbling up to their immediate container.
Question
Which two characteristics are true for Lightning Web Component custom events? Choose 2 answers
Options
- AData may be passed In the payload of a custom event using a wire decorated properties.
- BBy default a custom event only propagates to its immediate container and to its immediate child
- CBy default a custom event only propagates to it's immediate container.
- DData may be passed in the payload of a custom event using a property called detail.
How the community answered
(34 responses)- A3% (1)
- B88% (30)
- C9% (3)
Why each option
Lightning Web Component custom events can pass data using the `detail` property, and when configured to propagate, their scope is typically limited to bubbling up to their immediate container.
Data may not be passed in the payload of a custom event using `wire` decorated properties; `wire` is used for adapting a Salesforce function to a component's property or function, not for event payloads.
Lightning Web Component custom events, when configured to propagate (e.g., with `bubbles: true`), will typically propagate up the DOM tree to their immediate container, meaning the parent component. Events that are not `composed` are generally confined to the shadow DOM and the immediate host, ensuring a limited scope unless explicitly configured otherwise.
The default behavior for LWC custom events is `bubbles: false` and `composed: false`, meaning they do not propagate beyond the component that dispatches them, making the statement that they propagate to the immediate container by default incorrect.
Custom events in Lightning Web Components utilize the `detail` property of the `CustomEvent` object to pass data from the child component that dispatches the event to any parent component that is listening for it, allowing for flexible communication between components.
Concept tested: LWC custom event propagation and data passing
Source: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.events_create_dispatch
Topics
Community Discussion
No community discussion yet for this question.