There are five types of callback functions :
- Constructor()
- connectedCallback()
- disconnectedCallback()
- render()
- renderCallback()
constructor()
- Called when the component is created.
- This hook flows from parent to child, which means that it fires in the parent first.
- You can’t access child elements because they don’t exist yet. Properties aren’t passed yet, either. Properties are assigned to the component after construction and before the connectedCallback() hook.
- Called when the element is inserted into a dom.
- This hook flows from parent to child.
- You can’t access child elements because they don’t exist yet.
The connectedCallback() hook is invoked with the initial properties passed to the component.
- Called after every render of the component.
- This lifecycle hook is specific to Lightning Web Components, it isn’t from the HTML custom elements specification.
- This hook flows from child to parent.
- Call this method to update the UI.
- It may be called before or after connectedCallback().
- It’s rare to call render() in a component. The main use case is to conditionally render a template.
disconnectedCallback()
- Called when the element is removed from a document.
- This hook flows from parent to child.
- Use disconnectedCallback() to clean up work done in the connectedCallback(), like purging caches or removing event listeners.
- Called when a descendant component throws an error.
- The error argument is a JavaScript native error object, and the stack argument is a string.
- This lifecycle hook is specific to Lightning Web Components, it isn’t from the HTML custom elements specification.
Thank you!
No comments:
Post a Comment