Lightning Web Component

Quick Start: Lightning Web Components

Lightning Web Components

Lightning WebComponent

Introducing of Lightning Web Component

Now, you can build Lightning Components using two programming models:

  • Lightning Web Components (use core Web Components standards)
  • Aura Components

What is Lightning Web Component or LWC?

A lightning web component that includes an HTML file, a JavaScript file, and a metadata configuration file. Lighting Web Components are custom HTML elements built using HTML and modern JavaScript. The files must use the same name so the framework can auto-wire them.

lightning web components

Power of LWC:

  • HTML Templates

The power of Lightning Web Components is using template tag. Content inside a template tag will not be rendered. The content can be visible and rendered later by using Javascript.

  • CSS

In Lightning web Components, you can use Lightning Design System or Custom Css.

  • JavaScript

In Lightning Web Components, JavaScript files are in ES6 modules.

  • Composition

You can add components to Aura Component, Aura App and Lightning Web Component.

  • Access Static Resources, Labels, Internationalization Properties, and User IDs
  • Component Lifecycle

Why Lightning Web Componets(LWC)?

  • In 2014, Web Standards had limited functionality. So, various framework came to fulfil the gap like ReactJs, CommonJs etc.
  • Aura framework was also part of that initiative where they push web standards to build enterprise applications.
  • Fast Forward to today and much has changed.
    • Web Standards had a rich set of functionality, supported by Native Browsers.
    • Templating, CustomElements, ShadowDom, classes to name few.
  • So, why Salesforce turns to modern JavaScript and introducing Lightning Web Components.
  • Lightning Web Components takes the best of modern JavaScript and provides only what’s necessary to perform well in browsers supported by Salesforce.

Let’s see how to Create Lightning Web Component

Step 1) Setup Salesforce Dx in VSCode

salesforce extension pack
lightning web component
salesforce cli integration

Step 2) Upgrade to Pre-release Org

sfdx plugins:install salesforcedx@pre-release

salesforce plugin install
  • Enable the domain in your developer org.
deploy organization

Step 3) Create SalesforceDX Project

  • Open VSCode. Press “CTRL+SHIFT+P” and then enter “SFDX:Create Project with Manifest”. Then enter a project name and select folder.
create project with manifest
LWC recipes
  • Authorize an Org

Press “CTRL+SHIFT+P” and then enter “SFDX:Authorize an Org”.

sfdx authorize an org
authorize org name

Step 4) Finally, Create your first Lightning Web Component.

  • Press “CTRL+SHIFT+P” and then enter “SFDX: Create Lightning Web Component”.
create lightning web components
  • Then Select “lwc” folder.
select lwc folder
  • Then enter your Lightning Web Component Name. Please use camelCase for Lightning Web Components.It’s the best practice.
create hello world component
  • Let’s see your Lightning Web Component under “lwc” folder.

Step 5) Now, Lightning Web Component created. Let’s see how to use Lightning Web Component.

  • Put this code into helloWorld.html

  • Put this code into helloWorld.js

  • Put this into helloWorld.js-meta.xml

Step 6) Finally, deploy your component into Developer Org.

Step 7) Go to your Developer Org.

  • Click App Launcher Icon and then Select Sales App.
  • Then Click at Setup Icon and select edit page.
  • Then Drag “helloWorld” Component at pageLayout. After that, click at Activation and choose “OrgDefault”.Next, Activate.

Note: Domain is enabled in your Org. Else Custom Component will not be visible in your Org.

Here is your first Lightning Web Component.

Back to list

Leave a Reply

Your email address will not be published. Required fields are marked *