Salesforce Decode
Salesforcedecode
Back to questions
LWCBeginnerlifecycleconnectedCallback

What are lifecycle hooks in LWC?

Real World Scenario

You must load data when a component appears on a tab. You explain connectedCallback.

Expected Answer

• connectedCallback runs when component inserts into DOM—common place to start data load • renderedCallback runs after every render—avoid heavy logic here to prevent loops • disconnectedCallback cleans timers or subscriptions when component removes • constructor runs early—avoid DOM access or @wire side effects there • Use lifecycle hooks instead of outdated Aura init patterns

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Yes for initial load. Handle errors and loading flags so template does not flash empty content awkwardly.

Architect Perspective

connectedCallback for init, renderedCallback rarely—safe beginner lifecycle guidance.