how to import js via script in react
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"; this.div.appendChild(script); }
render() {
return (
<div className="App" ref={el => (this.div = el)}> <h1>Hello react</h1>
{/* Script is inserted here */}
</div>
);
}
}
export default App;import { useEffect } from 'react';
const useScript = url => {
useEffect(() => {
const script = document.createElement('script');
script.src = url;
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
}
}, [url]);
};
export default useScript;
Also in JavaScript:
- exponent javascript
- convert timestamp to date js
- jquery for bootstrap 4
- how to set input of time type to current time on initialization
- angular input value
- react map
- flutter reorder map by key
- Should I learn Javascript?
- date picker type react
- discord.js custom create channel
- try catch javascript
- cut text if too long javascript
- socket io query
- spreadjs autofit column with minimum
- web worker multiple data
- insert a data into mongo using express
- how to kill all node processes
- implement the remove property function
- javascript round up
- find even numbers in an array javascript
- javascript switch case regex
- click listener on by class name in javascript
- react create list of array in react
- javascript get last word in string