I have gone through 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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI have gone through 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.
Additionally to what you found online:
LightningElement is the base class for Lightning web components, which allows us to use connectedCallback().
In other words it's a JavaScript class that allows you to leverage on 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 web component.
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 extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration.
If we look at the stacktrace(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.