To import a class, function, or variable declared in a module, use the
import statement. To allow other code to use a class, function, or variable declared in a module, use the
componentName.js, such as
The core module in Lightning Web Components is
import statement imports
LightningElement from the
LightningElement is a custom wrapper of the standard HTML element.
export default keywords export a
MyComponent class for other components to use. The class must be the default export for UI components. Exporting other variables or functions in a UI component isn’t currently supported.
The convention is for the class name to be Pascal Case, where the first letter of each word is capitalized. For
myComponent.js, the class name is
- The component’s public API via public properties and methods annotated with
- Event handlers
myComponent.js file. However, the code in these files is for the component’s own use and can’t be shared.
To share code between components, create an ES6 module and export the variables or functions that you want to expose.
An ES6 module is a file that explicitly exports functionality that other modules can use. Modules make it easier to structure your code without polluting the global scope.