0

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)

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.