We can use third-party JavaScript libraries with Lightning web components. For example, we can use a library with interactive charts and graphs or a library that reduces code complexity.
Steps to be followed:
Download the library from the third-party library's site.
Upload the library to your Salesforce organization as a static resource, which is a Lightning Web Components content security policy requirement.
In a JavaScript class that extends LightningElement:\n
Import the library by its static resource name.
For example, if you named the static resource myLib:
import myLib from '@salesforce/resourceUrl/myLib';
Import methods from the platformResourceLoader module.
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
4. Load the library and call its functions in a then() method.
loadScript(this, myLib + '/myLib.js').then(() => {
let result = myLib.myFunction(2,2);
});
What we are trying to achieve:-
Steps taken to achieve this functionality are mentioned below :
Step 1:- Save the JS library as static resource in your org as shown below :
No comments:
Post a Comment