Exam B2B-Commerce-Developer Topic 3 Question 121 Discussion

Actual exam question for Salesforce's B2B-Commerce-Developer exam
Question #: 121
Topic #: 3
A developer is building a custom component in Lightning web components (LWC) that has a grandchild component that needs to pass information to the grandparent component. What is the correct way to demonstrate the passing of a message from the grandchild component to the grandparent component?

Suggested Answer: B Vote an answer

Explanation
The correct way to demonstrate the passing of a message from the grandchild component to the grandparent component in LWC is to use the PubSub library. The PubSub library is a utility that enables Lightning web components to communicate across the DOM tree without using intermediaries. The grandchild component can publish a message to a channel, and the grandparent component can subscribe to that channel and receive the message. This way, the communication is decoupled and does not depend on the component hierarchy.
Option B shows the correct syntax for using the PubSub library to pass a message from the grandchild component to the grandparent component. Option A is incorrect because it uses the @api decorator to expose a property on the grandchild component, which is not a valid way to communicate with the grandparent component. Option C is incorrect because it uses the @wire decorator to wire a property on the grandchild component to a function on the grandparent component, which is also not a valid way to communicate with the grandparent component. Option D is incorrect because it uses the @track decorator to track a property on the grandchild component, which is not a valid way to communicate with the grandparent component. References: Communicate Across the DOM |Lightning Web Components Developer Guide, Child to grandparent communication in LWC, PubSub Library for Lightning Web Components

by Myra at May 21, 2025, 03:51 AM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

Contact Us

If you have any question please leave me your email address, we will reply and send email to you in 12 hours.

Our Working Time: ( GMT 0:00-15:00 ) From Monday to Saturday

Support: Contact now 

日本語 Deutsch 繁体中文 한국어