What is Lightning Element in Lightning Web Component

1.6K    Asked by BrianKennedy in Business Analyst , Asked on Jun 1, 2021

 I have gone through the definition of LightningElement but unable to understand it clearly. Definition LightningElement is a custom wrapper of the standard HTML element.It extends element to create a JavaScript class for a Lightning web component.

Answered by Crowny Hasegawa
  In other words it's a JavaScript class that allows you to leverage it when you extend it. Once you extend it the methods from that class become immediately available to you. Such as connectedCallback(), renderedCallback(), disconnectedCallback(), errorCallback(error, stack), etc.

Additionally it's necessary to extend this class to supply a JS controller for your lightning element.

If I erase the extends part from export default class App extends LightningElement { I get the following error: TypeError: class App {} is not a valid component, or does not extend Lightning element from "lwc". You probably forgot to add the extend clause on the class declaration. If we look at the stack trace(I'm doing this in LWC Playground) we can see that this error comes from a file called engine.js. That file has over 6000 rows so it is beyond my ability to comprehend it but maybe somebody else who is more familiar can add up to my answer.



Your Answer

Interviews

Parent Categories