ExamGecko
Question list
Search
Search

List of questions

Search

Question 193 - Certified B2B Commerce Administrator discussion

Report
Export

Which two blocks of code are needed to implement a custom getter in a Lightning web component?

A.
set rows(value) { this.state.rows = value; }
Answers
A.
set rows(value) { this.state.rows = value; }
B.
get rows() { return this.state.rows; \ }
Answers
B.
get rows() { return this.state.rows; \ }
C.
@api f set rows(value) { A this.state.rows = value; }
Answers
C.
@api f set rows(value) { A this.state.rows = value; }
D.
@api get rows() { return this.state.rows; }
Answers
D.
@api get rows() { return this.state.rows; }
Suggested answer: B, D

Explanation:

A custom getter is a JavaScript function that returns a computed value based on some logic. To implement a custom getter in a Lightning web component, we need two blocks of code: one to define the getter function with the @api decorator, and one to access the getter in the HTML template. The @api decorator makes the getter public and reactive, which means that the component re-renders when the getter value changes. The getter function must start with the keyword get, followed by the name of the property. The HTML template can access the getter value by using curly braces and the property name. For example, if we have a custom getter named rows that returns an array of data, we can define it in JavaScript as:

@api get rows() { return this.state.rows; }

And we can access it in HTML as:

{rows}

Therefore, the correct blocks of code are B and D.

asked 23/09/2024
Anand R
37 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first