In this post we will talk about Lightning Web Components Naming Convention rules. We will also talk about example of PascalCase, camelCase or kebab-case and how those naming convention rules works in LWC.
Lets see what is the naming convention :
Use camel case to name your component and use kebab-case to reference a component in the markup. For example
Java Script Class name should be in PascalCase like below example :
camelCase : Each word in the middle of the respective phrase begins with a capital letter. for example apexHours.
PascalCase: It is same like Camel Case where first letter always is capitalized. for example ApexHours.
kebab-case: Respective phrase will be transferred to all lowercase with hyphen(-) separating words. for example apex-hours.
Thanks.
Amit Chaudhary
Components Bundles
Lightning web component bundles include all below files by default. Its also have some Optional component like CSS, SVG Icon.Lets see what is the naming convention :
Naming Convention / Rules for Components Bundles
- Component name Must begin with a lowercase letter
- Name must contain only alphanumeric or underscore characters
- Can’t contain a hyphen (dash)
- Must be unique in the namespace (No other Aura or LWC can have this name)
- Can’t include whitespace
- Can’t end with an underscore
- Can’t contain two consecutive underscores
- Folder and files names must have same “prefix name”.
HTML File
Use camel case to name your component and use kebab-case to reference a component in the markup. For example
JavaScript File
Java Script Class name should be in PascalCase like below example :
CSS File
- Needs to be created in the component bundle
- Has the same name as the component
- Uses standard CSS syntax
- Unlike Aura, no need for .THIS
What is the different between camelCase, PascalCase and kebab-case ?
camelCase : Each word in the middle of the respective phrase begins with a capital letter. for example apexHours.
PascalCase: It is same like Camel Case where first letter always is capitalized. for example ApexHours.
kebab-case: Respective phrase will be transferred to all lowercase with hyphen(-) separating words. for example apex-hours.
Case Name | camelCase | PascalCase | kebab-case |
Example | helloWorld | HelloWorld | hello-world |
Where to use | Folder File Names Property name in JS |
Class in Java Script | Component
reference in markup HTML attribure name |
Please check below post on Lightning Web Components:-
- Lightning Web Components ( LWC ) in Salesforce with Non-Scratch Org
- Invoke Apex Controller from Lightning Web Component | Lightning Web Component inside Another LWC
- Design attributes in Lightning Web Components | CSS and SVG Files | Lightning Web Components | targetConfigs
- How to get current user id in lightning web component | Access logged in user ID in LWC
- Toast Notification in Lightning Web Components | ShowToastEvent | (LWC)
- Lightning Web Components Best practices
- Events in Lightning web components (LWC) | Communicate with Events
- Lightning datatable In Lightning Web Components | lightning datatable inline edit
- Lightning Message Service (LMS) | MessageChannel
Thanks.
Amit Chaudhary
No comments:
Post a Comment