ExamGecko
Question list
Search
Search

List of questions

Search

Question 224 - Certified B2B Commerce Administrator discussion

Report
Export

A developer is building a custom component in Lightning web components (LWC) that needs to fetch data from an API.

Which lifecycle hook should the developer use to make the API call?

A.
connectedCallback
Answers
A.
connectedCallback
B.
renderedCallback
Answers
B.
renderedCallback
C.
errorCallback
Answers
C.
errorCallback
D.
disconnectedCallback
Answers
D.
disconnectedCallback
Suggested answer: A

Explanation:

The connectedCallback lifecycle hook is invoked when a Lightning web component is inserted into the DOM. This is the best time to make an API call, as the component is ready to render data from the server.The other lifecycle hooks are not suitable for making API calls, as they either occur after the component is rendered (renderedCallback), when an error occurs (errorCallback), or when the component is removed from the DOM (disconnectedCallback)1.Reference:1: Call Apex Methods - Trailhead2

asked 23/09/2024
Dimitri Bennett
35 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first