September 11, 2023
Lightning Web Component(LWC):
It is a new web programming model for developing lightning components on salesforce platform. This framework is built on HTML, CSS and JavaScript. It uses custom elements like templates, modules, shadow DOM, and other new language constructs of ECMAScript7.
Bundle description
- Component .HTML //HTML file created by default
- Controller .JS //JavaScript created by default
- JS-meta .xml //created by default
*if you want to use your component inside the app page or record page or homepage or community then you need to specify those configuration in the js-meta.xml file.*
- Style .CSS //css file manual creation
- Icon .SVG //svg file manual creation
LWC Lifecycle Hooks
1- Constructor
- Called when the component is created.
- Flow from parent to child.
constructor(){ super(); }
2- connectedCallback
- Called when the element is inserted into a document.
- Flows from parent to child.
- Perform initialization tasks, such as fetch data, set up caches, or listen for events.
connectedCallback(){ let con=this.template; console.log(con.isConnected); //to check whether a component is connected to the DOM or not }
3- renderedCallback
- called after every render of the component.
- flows from child to parent.
- getting called more than once.
- use a private boolean property like hasRendered to track whether renderedCallback() has been executed.
- first time renderedCallback() executes, perform the one-time operation and set hasRendered = true.
renderedCallback(){ }
4- render
- Call this method to update the UI. It may be called before or after connectedCallback().
- It’s rare to call render() in a component.
- To show dynamic HTML template.
render(){ }
5- disconnectedCallback
- Called when the element is removed from a document.
- flows from parent to child.
disconnectedCallback(){ }
6- errorCallback
- Called when a descendant component throws an error.
- The error argument is a JavaScript native error object and the stack argument is a string.
errorCallback(error, stack){ }
Latest Post
About Me
Welcome to an Aimer's weblog :)
Hi! Asif Parvez here, I'm from West Bengal's Howrah. I have extensive experience in Apex, Integration (REST API), LWC, ADMIN and working as Senior Salesforce Developer for Dazeworks Technologies(An iLink Digital Company). I am also a content creator and blogger.
I have three certifications(PD-I, PD-II, Salesforce Associate).
Hey Asif,
Amazing write-up !!
Thanks Somya!
Very well explained
Thanks Sirisha!