Answers for "external script in react"

1

external script in react

componentDidMount() {
    const script = document.createElement("script");
    script.async = true;
    script.src = "https://some-scripturl.js";
    script.onload = () => this.scriptLoaded();



    //For head
    document.head.appendChild(script);

    // For body
    document.body.appendChild(script);

    // For component
    this.div.appendChild(script);

  }
Posted by: Guest on June-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language