1.0.3 • Published 3 years ago

usedynamicscript v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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