Skip to main content

LWC Decorators

Decorators :



In LWC decorators are used to add functionality to a property or function.

There are three types of decorators :
1. @track
2. @api
3. @wire

@track : It is used to make properties or methods in LWC is private. This properties is not accessible outside the LWC in which it is declared.

@api : It is used to make properties or methods in LWC is public. This way they are accessible outside of the component in which they are declared.
For ex : parent component can set the value of the properties in the child component.

@wire : It is used to read the Salesforce data from apex class into LWC. It is generally used while making the server call to apex class.

LWC Properties :
There are two type of LWC properties.
1. Reactive Properties
2. Non-Reactive Properties

Reactive Properties : In case of reactive properties , value of the properties change when the component re-render. There are two types of Reactive Properties.
1. Public properties  - Decorated with @api.
2. Private properties - Decorated with @track.

Non-Reactive Properties : Non-Reactive properties are declared without any decorators , so even if the value of the non-reactive properties changes component doesn't get re-render.

Other Useful Blog

Lightning Component

Happy Learning !!

Comments

Popular posts from this blog

LWC Show Records In Table

Requirement : ‹ › Create a LWC component which will show the most recently created 10 Opportunity from the org and show them in table having Name , Close Date , Stage Name , Type and Create . or in other words Show Opportunity data in table format. cmpOpportunityRecords.html < template >      < lightning-card   title = "Opportunity Records"   icon-name = "standard:opportunity" >                  < lightning-datatable                            data = {data}                columns = {columns}                key-field = "Id" >          </ lightning-...

LWC Development Environment

Requirement : ‹ › Setup LWC Development Environment  1. VS (Visual Stdio) Code 2. Salesforce CLI Download and install the latest version of  Visual Studio Code . Open the Visual Studio Code and add extensions by clicking on the extensions icon present on the left side of the VS code editor. Search for  Salesforce Extension Pack  and install the extension. After that install  Lightning Web Components extension. Once you done with installing the above two extensions Re-launch the VS code editor. Now it’s time to check that our environment is ready for creating Lightning Web Components by pressing  Command + Shift + P  on  macOS or Ctrl + Shift + P  on Windows and type  sfdx . Hola..!! you are now ready to create your Lightning Web Components. Creating SFDX Project First create a folder somewhere on your machine and name it  trailblazer  or anything of your choice. Navigate to that folder from VS code ...

LWC Component Only

Requirement : ‹ › Create a LWC having two input fields which will take two number as input and show result, addition happen on button click. cmpAddition.html < template >      < lightning-card   title = "Addition"   icon-name = "custom:custom62" >                   < p   class = "slds-p-horizontal_small" >              < lightning-input                    value = {firstNumber}                    name = "fnumber"                    label = "First Number"             ...