What are all the LWC lifecycle hooks and in what order do they fire?
Suggested answer
LWC lifecycle hooks in order:
1. constructor(): Component creation. Call super() first. Cannot access child elements or external DOM.
2. connectedCallback(): Component inserted into the DOM. Access to this.template for the component's own shadow root. Safe for data loading and event subscriptions.
3. render() (internal): The framework calls the template's render.
4. renderedCallback(): After every render (initial and re-renders). Can access the rendered DOM. Avoid state changes that cause re-renders (infinite loop risk).
5. disconnectedCallback(): Component removed from DOM. Clean up: unsubscribe from LMS channels, cancel timers.
6. errorCallback(error, stack): Catches errors thrown by child components. Acts as an error boundary. For parent-child relationships: parent constructor → parent connectedCallback → child constructor → child connectedCallback → child renderedCallback → parent renderedCallback.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.