Friday, January 13, 2023

Lightning web components best practices


1. Use proper Naming conventions while creating lightning web components.
  • Must begin with a letter
  • Must contain only alphanumeric or underscore characters
  • Must be unique in the namespace
  • Can’t include whitespace
  • Can’t end with an underscore
  • Can’t contain two consecutive underscores
  • Can’t contain a hyphen (dash)
  • use camelCase format, start the component name from lowercase
  • Ex: helloWorld
2. Use @track only, if you want to render the view on changes of tracked variables. for static and non-render based variables just define like below.

HTML file:
<template>
   <h1>{title}</h1>
</template>
js file:
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {
   title ='Hello world';

No comments:

Post a Comment