GSalesforceGyan
← Browse learning guides

LWC

Lifecycle hooks and render loops

Understand initialization, DOM access, and cleanup.

By Vishal Verma · Reviewed October 5, 2026

Practice these questions aloud. Give the principle, explain a concrete example, and finish with how you would verify the result.

1. What belongs in connectedCallback?

Suggested answer: Initialization when the component is inserted into the DOM. It may run more than once, so avoid duplicate subscriptions or work. Child template elements are not ready for access there.

Scenario / follow-up: Use a property setter when initialization depends on changing public input.

2. When should you use renderedCallback?

Suggested answer: For work that needs the rendered DOM. It can run repeatedly; guard one-time initialization and avoid changing state that causes another render.

Scenario / follow-up: An endless server request loop often comes from changing reactive configuration during rendering.

3. What belongs in disconnectedCallback?

Suggested answer: Clean up resources the component owns, such as timers, external listeners, and subscriptions that require explicit disposal.

Scenario / follow-up: Explain what happens when the user navigates away and returns.

Reviewed October 5, 2026. Check the linked documentation for your org’s API version and supported features.

Official reference

Read the Salesforce documentation or Trailhead resource