Bundle external JavaScript(from a cdn) into a React component

前端 未结 4 477
北恋
北恋 2021-02-05 21:08

What options are there to bundle an external javascript sdk into a React Component?

I have tried including the javascript in the index.html and referring to it through

4条回答
  •  后悔当初
    2021-02-05 21:47

    try something like this:

    componentDidMount () {
       const script = document.createElement("script");    
    
       script.src = "https://cdnjs.cloudflare.com/somelibrary1.min.js";
       script.async = true;
    
       document.body.appendChild(script2);
     }
    

提交回复
热议问题