React Loading scripts in head or body

12 min read
import React,{Component} from "react";
import ReactDOM from "react-dom";

import "./styles.css";

class App extends Component {
  componentDidMount() {
    const script = document.createElement("script");
    script.async = true;
    script.src = "https://some-scripturl.js";
    //For head
    document.head.appendChild(script);
    // For body
    document.body.appendChild(script);  }
  render() {
    return (
      <div className="App">
        <h1>Hello react</h1>
      </div>
    );
  }
}