title: How to load custom script in react?
body: <p>This is somewhat similar to this question:</p>
  <p><a href="https://stackoverflow.com/questions/34424845/adding-script-tag-to-react-jsx">Adding script tag to React/JSX</a></p>
  <p>But in my case I am loading a script like this:</p>
  <pre><code>&lt;script&gt;(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','ID');&lt;/script&gt;
  &lt;!-- End Google Tag Manager --&gt;
  </code></pre>
  <p>Now I know there is a npm package for the google tag manager but I am curious if I would like to do this in a custom way how would I go about?</p>
  <p>In the above question I see a lot of:</p>
  <pre><code>const script = document.createElement(&quot;script&quot;);
  
  script.src = &quot;https://use.typekit.net/foobar.js&quot;;
  script.async = true;
  
  document.body.appendChild(script);
  </code></pre>
  <p>Which is fine but if I have a function inside of the loaded script how would I go about executing this correctly?</p>