ExamGecko
Question list
Search
Search

List of questions

Search

Question 187 - Certified B2B Commerce Administrator discussion

Report
Export

What should a developer do to expose a public property in a Lightning web component? 0m 23s

A.
Decorate the field with @property
Answers
A.
Decorate the field with @property
B.
Decorate the field with @track
Answers
B.
Decorate the field with @track
C.
Decorate the field with @public
Answers
C.
Decorate the field with @public
D.
Decorate the field with @api
Answers
D.
Decorate the field with @api
Suggested answer: D

Explanation:

To expose a public property in a Lightning web component, the developer should decorate the field with @api. The @api decorator marks a public reactive property that can be set by another component that uses this component.The property value is passed from the owner component to the child component3. For example, if a parent component has a property called message, it can pass its value to a child component by using an attribute with the same name in the HTML template:

<c-child message={message}></c-child>

The child component can access this value by declaring a public property with @api:

import { LightningElement, api } from 'lwc'; export default class Child extends LightningElement { @api message; }

The other decorators are not used to expose public properties in a Lightning web component.The @property decorator is used to define private reactive properties that are internal to the component4.The @track decorator is used to mark private fields as reactive, so that changes to their values trigger a re-render of the component5. The @public decorator does not exist in Lightning web components.Reference:Public Properties,Private Properties,Reactive Properties

asked 23/09/2024
JASON HOLT
34 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first