How to include external JavaScript library in reactjs
First of all, don't use the source file. Just npm install jspdf --save
like any other package, and import it with var pdfConverter = require('jspdf');
Secondly, you're missing a () in this line var doc = new pdfConverter.jsPDF('p','pt');
Do something like this:
var converter = new pdfConverter();
var doc = converter.jsPDF('p', 'pt');
How to make external javascript file work in ReactJs?
We use the DOM method to load external JS in our ReactJS app.
For example, https://api.mesibo.com/mesibo.js
is an external JS library provided by mesibo, we load it as following
const externalJS = "https://api.mesibo.com/mesibo.js";
const script = document.createElement("script");
script.src = externalJS;
document.body.appendChild(script);
loading external js library in reactjs
my solution was to put my deploy the sdk project which I had into npm
and npm install it
Reactjs : import and load external js library minified files put inside src
Put the js file into the public folder, then import the js file.
in index.html
<head>
<!-- If your application is built via create-react-app -->
<script src="%PUBLIC_URL%/js/file1.min.js"></script>
<!-- or custom webpack -->
<script src="/js/file1.min.js"></script>
</head>
Related Topics
How to Reload Datatables from Another Ajax Request With Onclick
Show Base64 Pdf Data Using Window.Open on Chrome New Version
How to Find an Exact Word in a String
Disable Chrome Strict Mime Type Checking
How to Use Aria-Expanded="True" to Change a CSS Property
Import Image from Json Source (Create-React-App)
Ngx-Datatable Set Column Width Dynamically
How to Know If Two Arrays Have the Same Values
How to Extract Data from Json Nested Objects
Removing Number from Notification Icon
Set Cookie on Page Load and Hide Div If Cookie Is Present
Can We Map Over Two Arrays At Same Time in Js
Method for Splitting String into Separate Cells in Sheets/App Script
How to Properly Import Function in a Reactjs File
Most Efficient Method to Groupby on an Array of Objects
How to Remove Errors Warnings from Console
Reactjs - How to Update Nested and "Normal" State Properties
Regular Expression Using JavaScript for Removing the Special Characters