the venom
the venom

Reputation: 771

how to load an external script with react?

I have just cloned create-react-app and have put an external script inside the public/index.html

  <head>
    <script src="https://myexternalscript"></script>

the script that I'm using then allows me to use their API in the console and on the page

however, the problem is when I try and use it in the react app. it says that Word is not defined. for example lets say it was Bootstrap inside my react component

  open() {
    Bootstrap.dostuff();
  }

it is saying Boostrap is not defined. but it's clearly loaded coz I can access in the console. how do I use this in my react app?

(bootstrap is just an example, I can't say the actual name as it's private API)

Upvotes: 0

Views: 199

Answers (1)

tech4him
tech4him

Reputation: 980

Use window.Bootstrap, instead of just Bootstrap. When you simply say Bootstrap, JavaScript steps up in scope until it find a scope which contains a Bootstrap variable. If you specify window, then it will simply access the global scope directly.

Upvotes: 1

Related Questions