PDI · Question #23
A developer is creating an app that contains multiple Lightning web components. One of the child components is used for navigation purposes. When a user click a button called.. component, the parent c
The correct answer is D. Create a custom event.. Child Lightning Web Components communicate with parent components by dispatching custom events, which the parent then listens for and handles.
Question
A developer is creating an app that contains multiple Lightning web components. One of the child components is used for navigation purposes. When a user click a button called.. component, the parent component must be alerted so it can navigate to the next page. How should this be accomplished?
Options
- AFire a notification.
- BUpdate a property on the parent.
- CCall a method in the Apex controller.
- DCreate a custom event.
How the community answered
(15 responses)- C7% (1)
- D93% (14)
Why each option
Child Lightning Web Components communicate with parent components by dispatching custom events, which the parent then listens for and handles.
Firing a notification typically refers to showing a toast message to the user, not a direct programmatic communication channel between two components for internal application logic.
Child components cannot directly update properties on a parent component; properties flow unidirectionally from parent to child in Lightning Web Components.
Calling a method in the Apex controller handles server-side operations and database interactions, but it does not facilitate direct communication between client-side Lightning web components.
To alert a parent component from a child component in LWC, the child component should dispatch a custom event, which the parent component then registers a listener for and handles to trigger its navigation logic.
Concept tested: LWC Child-to-Parent Communication
Source: https://developer.salesforce.com/docs/component-library.en-us.lwc.meta/lwc/lwc_events_create_dispatch.htm
Topics
Community Discussion
No community discussion yet for this question.