Lifecycle hooks in Lightning Web Component : jayakrishnasfdc
Lifecycle hooks in Lightning Web Component
by: jayakrishnasfdc
blow post content copied from Jayakrishna Ganjikunta
click here to view original post
December 06, 2020 at 12:31PM
Click here for more details...
=============================
The original post is available in Jayakrishna Ganjikunta by jayakrishnasfdc
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================
by: jayakrishnasfdc
blow post content copied from Jayakrishna Ganjikunta
click here to view original post
A lifecycle hook is a callback method triggered at a specific phase of a component instance’s lifecycle.
Lightning web components have a lifecycle managed by the framework. The framework creates components, inserts them into the DOM, renders them, and removes them from the DOM. It also monitors components for property changes. Generally, components don’t need to call these lifecycle hooks, but it is possible.
- constructor()
- connectedCallback()
- disconnectedCallback()
- render()
- renderedCallback()
- errorCallback(error, stack)
This diagram shows the flow of the component lifecycle from creation through render.
This diagram shows what happens when a component instance is removed from the DOM.
- Run Code When a Component Is Created
Theconstructor()
method fires when a component instance is created. Don’t add attributes to the host element during construction. You can add attributes to the host element in any other lifecycle hook. - Run Code When a Component Is Inserted or Removed from the DOM
TheconnectedCallback()
lifecycle hook fires when a component is inserted into the DOM. ThedisconnectedCallback()
lifecycle hook fires when a component is removed from the DOM. - Run Code When a Component Renders
TherenderedCallback()
is unique to Lightning Web Components. Use it to perform logic after a component has finished the rendering phase. - Handle Component Errors
TheerrorCallback()
is unique to Lightning Web Components. Implement it to create an error boundary component that captures errors in all the descendent components in its tree. It captures errors that occur in the descendant’s lifecycle hooks or during an event handler declared in an HTML template. You can code the error boundary component to log stack information and render an alternative view to tell users what happened and what to do next.
We will see one by one in coming articles..
December 06, 2020 at 12:31PM
Click here for more details...
=============================
The original post is available in Jayakrishna Ganjikunta by jayakrishnasfdc
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================
Post a Comment