Salesforce Interview Questions & Answers Book is now available!

Grab Now

LWC

Difference between connectedCallback() and renderedCallback() in LWC

Let's look at what is the difference between connectedCallback() and renderedCallback() in LWC

By Teja, ex-Salesforce engineer · Updated April 11, 2021 · 1 min read

When the shadow dom is connected to the main document, at that moment a JavaScript method called connectedCallback() is invoked.

By the time this method gets invoked, we cannot write code that is trying to get reference to the tags, because the template is not yet loaded, it’s just connected to the main dom.

Likewise, when the shadow dom is completely rendered then the JavaScript method renderedCallback() is invoked. In this method, we can write code to get a references to the HTML and Custom Component tags.

Hope this was helpful!

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts