HTML5 & Web APIs (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Web Components Lifecycle Hooks.
senior LevelComponentsHooksLifecycle
In Simple Words: The 4 native lifecycle callback methods of custom elements:
connectedCallback(): Invoked each time the custom element is appended into a document-connected DOM tree. (Initialize listeners, fetch data).disconnectedCallback(): Invoked when removed from the DOM. (Clean up timers and event listeners).adoptedCallback(): Invoked when moved to a new document (e.g. across<iframe>boundaries).attributeChangedCallback(name, oldValue, newValue): Invoked when an observed attribute (listed instatic get observedAttributes()) is updated.