score:4

Accepted answer

you can use it in the following way:

function loadscript(url, callback){

    let script = document.createelement("script")
    script.type = "text/javascript";

    if (script.readystate){  //ie
        script.onreadystatechange = function(){
            if (script.readystate == "loaded" ||
                    script.readystate == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getelementsbytagname("head")[0].appendchild(script);
}

and then use this function on componentdidmount() to load the external script.


Related Query

More Query from same tag