CRT-450 practice question 2 of 30
A developer created a child Lightning web component nested inside a parent Lightning web component. The parent component needs to pass a string value to the child component. In which two ways can this be accomplished? Choose 2 answers
Full set: 201 questionsCommunication from a parent Lightning Web Component (LWC) to a nested child LWC is accomplished through two primary mechanisms. The first is declaratively, by setting a public property on the child component. The child exposes a property using the @api decorator, which the parent can then set in its markup. The second is imperatively, where the parent component gets a reference to the child and calls a public method, also exposed via the @api decorator, passing the string value as an argument. Both are standard, documented patterns for parent-to-child data flow.
1. Salesforce Lightning Web Components Developer Guide: For passing data via public properties. The guide states
"To expose a public property
decorate a field with @api. Public properties are reactive. If the value of a reactive property changes
the component’s template rerenders."
Source: Lightning Web Components Developer Guide
"Pass Data from Parent to Child with Public Properties".
2. Salesforce Lightning Web Components Developer Guide: For invoking methods on a child. The guide explains
"To expose a public method
decorate it with @api. Public methods are part of a component's public API. To communicate down the containment hierarchy
a parent component can call a public method on a child component."
Source: Lightning Web Components Developer Guide
"Call Methods on Child Components".
3. Salesforce Lightning Web Components Developer Guide: To differentiate from child-to-parent communication. The guide specifies
"A component dispatches an event to send data to a component in its container hierarchy. The CustomEvent interface lets you create your own events." This confirms events flow upwards.
Source: Lightning Web Components Developer Guide
"Communicate with Events".
Keep practicing
Take the free CRT-450 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-450 practice questions
- Question 4A developer needs to make a custom Lightning Web Component available in the Salesforce Cl…
- Question 6Given the following Apex statement: Account myAccount = [SELECT Id, Name FROM Account); W…
- Question 8Which action causes a before trigger to fire by default for Accounts?
- Question 9Universal Containers (UC) wants to lower its shipping cost while making the shipping proc…
- Question 10A custom picklist field, Pool Preference ¢, exists on a custom object. The picklist conta…
- Question 11Universal Containers decides to use exclusively declarative development to build out a ne…
