score:4
Accepted answer
you can use it in the following way:
function loadscript(url, callback){
let script = document.createelement("script")
script.type = "text/javascript";
if (script.readystate){ //ie
script.onreadystatechange = function(){
if (script.readystate == "loaded" ||
script.readystate == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //others
script.onload = function(){
callback();
};
}
script.src = url;
document.getelementsbytagname("head")[0].appendchild(script);
}
and then use this function on componentdidmount()
to load the external script.
Source: stackoverflow.com
Related Query
- Fixing 'define' is not defined no-undef in react create app third party imports
- add third-party js library to Create React App
- How to include third party js libraries in React app
- Add Service Worker to Create React App Project
- How to process 3rd party dependency's CSS in a Create React App application
- Create React Component Library using CRACO with Create React App
- Add craco webpack plugin by condition for create react app
- how initialize third party library (konvajs) in react hooks
- Initialise third party library using React hooks
- Facebook Create React App Build - Add Image As Prop Type
- How do I add WebPack polyfill to React App created with React Create App without ejecting?
- How to add a 3rd party Jquery Library in React Functionnal component?
- Add path when webpack creates static asset files react, create react app
- React Loses "this" In Callback From Third Party Library
- unable to add classes in react using create react app
- create and save csv file without any third party library in ReactJS
- Unexpected token "<" when importing from third party library into React project
- How to add TypeScript 3.7 Optional Chaining support to create react app project
- How can I add Vanilla JS to my react app to create Image Modal pop-ups?
- Using third party library with react js giving error
- how to add rules to ESLint in Create React App
- Webpack HMR with React and third party library
- create react app not picking up .env files?
- How to create a React app directly in the current folder
- What is the difference between NextJs and Create React App
- How to create multiple page app using react
- When to use a react framework such as Next or Gatsby vs Create React App
- React create app hot reload is not always working on linux
- Cannot find module 'caniuse-lite/dist/unpacker/agents' when running create react app
- The react-scripts package provided by Create React App requires a dependency:
More Query from same tag
- React Error (Only a ReactOwner can have refs.)
- JavaScript: Will a = Object.assign({}, a, {k: v}) mutate a?
- Material-UI multiple table collapse/expand
- the client is unable to receive the stack-trace of the exception from the server
- How to loop in into multiple elements using single useRef?
- React - How do I make an element disappear after animation ends?
- I have an array state of my react component, should I use Object.assign() when I add new item? I tried spread operator but see strange behavior
- Adding validation to simple React + Typescript application
- generate a image from scratch?
- MobX reset store to initial state
- reactjs + webpack + babel 7 Syntax error: The rest element has to be the last element when destructing
- Conditional addEventListener when div ID is at top of window
- React-router-dom Render props isn't returning any component
- react-router-dom Switch needs additional div wrapper
- How to create schema customization to use optional field "featureImage" from gatsby blog
- Filter products based on searchString and product size
- Format date pulled from API - React
- React hook for component "componentWillUnmount" lifecycle method
- Why my Webpack does not loading background image?
- How add dynamic id to FormattedMessage in react intl
- How do I use react custom hooks to make code reusable
- How to refactor all subfunction to make only one?
- callback function for setState only fills the last component's state to parent component's state on render
- REACT & Expressjs: Backend can't 'serve' static frontend
- How to properly delete object subfields when dispatching a new redux action?
- How would I pass info between two functions
- Why audio duration got changed
- How to loop through refs in React and get values?
- javascript react pass value from method
- how to uses ReactJS and Laravel