You need to sign in to do that
Don't have an account?
Jap Hendy Wijaya
LWC 3rd party library, how to know the function name ?
Hi All,
So i've been learning LWC, and got to the topic of using 3rd party library. i'm curious as to how do we know what function name to use in the 3rd library.
For example, i'm using axios to fetch data from external server
link: https://github.com/axios/axios
I'm configuring the js file of lwc, loadScript to point to '/axios-master/dist/axios.js'
I can call the function, namely axios({ url: ...}).then().catch()
But when i inspect the file axios.js inside folder dist, nowhere i can find the function with name axios, there is function with name Axios though (capitalized first letter). The curious thing is, if i call function Axios, it doesn't work in lwc.
Can somebody help to explain this to me, as i'm very curious how to know the function name to use.
Thank you very much friends.
So i've been learning LWC, and got to the topic of using 3rd party library. i'm curious as to how do we know what function name to use in the 3rd library.
For example, i'm using axios to fetch data from external server
link: https://github.com/axios/axios
I'm configuring the js file of lwc, loadScript to point to '/axios-master/dist/axios.js'
I can call the function, namely axios({ url: ...}).then().catch()
But when i inspect the file axios.js inside folder dist, nowhere i can find the function with name axios, there is function with name Axios though (capitalized first letter). The curious thing is, if i call function Axios, it doesn't work in lwc.
Can somebody help to explain this to me, as i'm very curious how to know the function name to use.
Thank you very much friends.
All Answers
Please follow below url:-
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_third_party_library
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
axios = static resource that contains: https://cdn.jsdelivr.net/npm/axios/dist/axios.js Result: toast + console.log 'get' is one of the returned methods
See, from your returned values, the function name is 'Axios' with capital A, so naturally we should use the function with that name right ? for example: Axios.get() / Axios.put() / Axios.post() / Axios() ..., but it's not working in LWC, instead of 'Axios' with capital A, i have to use 'axios' with lowercase a.
Although turns out, not all 3rd library use the module.exports.default in the dist file or in any entry point file.
We find that it is likely more reliable to look within the 'window' object, and see what name is loaded from the library to the component.