LWC lifecycle hooks interview questions
Lifecycle questions look easy until the follow-up: why does this renderedCallback run twice? Here is what each hook is for and the mistakes interviewers like to probe.
On this page (6 sections)
Interview questionsCommon MistakesRelated LWC Lifecycle Interview QuestionsFrequently Asked Questions about LWC Lifecycle InterviewsRelated CertificationsRelated ResourcesNew to this topic? Learn Lightning Web Components step by step before you practise.
Lifecycle hooks are where most LWC bugs happen: wrong hook for the wrong job leads to infinite loops, memory leaks, or empty data. These questions come up in almost every LWC interview.
01What are the lifecycle hooks in LWC?
What are the lifecycle hooks in LWC?
constructor → connectedCallback → render → renderedCallback → disconnectedCallback. errorCallback fires when a child component throws. Each hook has a specific purpose: constructor for init, connected for one-time setup, rendered for DOM access, disconnected for cleanup.
02What goes in constructor vs connectedCallback?
What goes in constructor vs connectedCallback?
Constructor runs once at component creation: use only for property initialisation, not DOM or @api access. connectedCallback runs when the component is inserted into the DOM: use it for fetching data, subscribing to events, registering message channels.
03Why is renderedCallback dangerous if not guarded?
Why is renderedCallback dangerous if not guarded?
It runs after every re-render. If you set a tracked property inside it, you trigger another render → infinite loop. Always guard with a boolean (this.hasRendered = true) so the work runs only once.
04What's the order when a child component is added?
What's the order when a child component is added?
Parent constructor → parent connectedCallback → parent render → child constructor → child connectedCallback → child render → child renderedCallback → parent renderedCallback. Knowing this order helps debug timing-related bugs.
05When does disconnectedCallback fire?
When does disconnectedCallback fire?
When the component is removed from the DOM: page navigation, conditional rendering, or unmount. Use it to unsubscribe from message channels, clear intervals, and release listeners. Skipping cleanup causes memory leaks.
06What is errorCallback?
What is errorCallback?
Boundary for child component errors. Define errorCallback(error, stack) on a parent: if any descendant throws during lifecycle or render, this catches it. Use it to show graceful fallback UI instead of a broken page.
07Can you make async calls in connectedCallback?
Can you make async calls in connectedCallback?
Yes, this is the standard place to call imperative Apex or fetch external data. The component renders immediately with empty/loading state, then re-renders when the promise resolves.
08Why doesn't @wire data appear in constructor?
Why doesn't @wire data appear in constructor?
Because @wire fires after the component is connected to the DOM, not at construction. Always reference wired data in connectedCallback or later, never in the constructor.
09How do you debug lifecycle order issues?
How do you debug lifecycle order issues?
Add console.log('component:hookName') inside each hook of parent and child. The browser console then shows exact firing order. For complex trees, this is the fastest debugging trick.
10What if you need to re-fetch data after a property changes?
What if you need to re-fetch data after a property changes?
Use a getter/setter on the @api property. In the setter, trigger your fetch. Or use @wire with reactive parameters which auto-refetch when the parameter changes.
Common Mistakes
Setting state in renderedCallback. Causes infinite loops without a guard.
DOM access in connectedCallback. DOM isn't ready yet.
Forgetting cleanup. Skipping disconnectedCallback causes leaks.
Frequently Asked Questions about LWC Lifecycle Interviews
Can I access this.template in connectedCallback?
No, the DOM isn't ready yet. Use renderedCallback for DOM access.
Does renderedCallback fire on parent re-renders?
Yes, every render. Always guard with a boolean.
Can I call setTimeout in connectedCallback?
Yes but clear it in disconnectedCallback to prevent leaks.
What's the difference between LWC and Aura lifecycle?
LWC has fewer, simpler hooks. Aura had init, render, rerender, etc. with more ceremony.
Are there hooks for parent property updates?
Use getter/setter pairs on @api properties to react to incoming changes.
Related Certifications
Tested in JavaScript Developer I and PD2. See certification guides.