Skip to main content

Posts

Showing posts with the label Reusable js

Share JavaScript Code Between LWC and Aura

To share JavaScript code between Lightning web components and Aura components, put the code in an ES6 module. To share an ES6 module: Create an ES6 module using the Lightning Web Components programming model. To use the code in a Lightning web component, import and reference it in the component’s JavaScript file. To use the code in an Aura component, use the same syntax that you use to import an Aura component and call its methods. Create a .js file, example: extendableJS const calculateMonthlyPayment = (principal, years, rate) => { if (principal && years && rate && rate > 0) { const monthlyRate = rate / 100 / 12; const monthlyPayment = (principal * monthlyRate) / (1 - Math.pow(1 / (1 + monthlyRate), years * 12)); return monthlyPayment; } return 0; }; export { calculateMonthlyPayment }; • Create a lwc which can use your . js funct

Translate