Working Implementation:
The following implementation in HTML file works. (Instructions from third party library)
<script src="https://cdn.somethirdpartyfile.js"></script>
<script>
const client = new myThirdParyClass({
param1: "test",
param2: "test"
});
</script>
Problem: Sandbox Link
I am using the below code to add a 3rd party library to my react code base.
index.html:
<script src="https://cdn.somethirdpartyfile.js"></script>
Component Code
useEffect(() => {
let script = document.createElement("script");
script.onload = function () {
const client = new myThirdParyClass({
param1: "test",
param2: "test"
});
};
// clean ups
return () => {
document.body.removeChild(script);
};
}, []);
But my react code throws an error saying myThirdParyClass is not defined. How can I initialize the third-party class in my React component?