Suggested answer

LWC lifecycle hooks: constructor(): Called when the component is created. Do not access the DOM or child components here. Call super() first. connectedCallback(): Called when the component is inserted into the DOM. Safe to access the component's own DOM (not children yet). Good for data fetching, event subscription, and initialisation. renderedCallback(): Called after every render. Use for post-render DOM manipulation. Be careful of infinite loops (avoid state changes that trigger re-renders here). disconnectedCallback(): Called when the component is removed from the DOM. Use for cleanup (unsubscribing from message channels, clearing timers). errorCallback(error, stack): Error boundary — catches errors from child components. Only available on components acting as error boundaries.

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.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.