How to Include External JavaScript Library in Reactjs

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, is an external JS library provided by mesibo, we load it as following

const externalJS = "";
const script = document.createElement("script");
script.src = externalJS;

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

<!-- 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>

Related Topics

Leave a reply