Lifecycle hooks in LWC
Lifecycle hooks in LWC
Lifecycle
Hooks
LWC
in
DHANANJAY AHER
Use of constructor:
the correct prototype chain and value for this. Always call super() before
touching this.
The connectedCallback() hook is invoked with the initial properties passed to the
component. If a component derives its internal state from the properties, it's better to
write the logic in a setter than in connectedCallback().
💻renderedCallback():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.A
component is rerendered when the value of a property changes and that property is
used either directly in a component template or indirectly in the getter of a property that
is used in a template. See Reactivity.If you use renderedCallback() to perform a one-
time operation, you must track it manually (using an initialRender private property, for
example). If you perform changes to reactive attributes, guard them or they can trigger
wasteful rerenders or an infinite rendering loop.Use renderedCallback() to interact
with a component's UI. For example, use it to:
Perform tasks not covered by our template declarative syntax, such as add a
:
Source https://developer.salesforce.com/docs/component-library/documentation/lwc/reference_lifecycle_hooks