usedynamicscript
v1.0.3
Published
React hook to dynamically import scripts
Downloads
13
Maintainers
Readme
useDynamicScript is a lightweight (~145 bytes) custom React Hook that can be used to dynamically import (and remove) JavaScript files.
Install
npm:
npm install --save usedynamicscript
Yarn:
yarn add usedynamicscript
Example
import useDynamicScript from "usedynamicscript";
import {useEffect} from "react";
function MyComponent(){
const [insert, remove] = useDynamicScript("https://localhost/myscript.js", "scriptId");
useEffect(() => {
insert();
return(() => remove());
}, [])
return <p>Hello World :)</p>
}
License
MIT © PandaSekh