Salesforce Platform Developer I (legacy) — Question 122
What are two best practices when it comes to Lightning Web Component events? (Choose two.)
Answer options
- A. Use event.detail to communicate data to elements in the same shadow tree.
- B. Use CustomEvent to pass data from a child to a parent component.
- C. Use event.target to communicate data to elements that aren't in the same shadow tree.
- D. Use events configured with bubbles: false and composed: false.
Correct answer: B, D
Explanation
Option B is correct because CustomEvent is specifically designed for passing data from a child to a parent component in Lightning Web Components. Option D is also correct as configuring events with bubbles: false and composed: false limits their propagation, which is a best practice in certain scenarios. Options A and C are incorrect because they do not align with best practices for event handling in Lightning Web Components.