usedynamicscript

1.0.3 • Public • Published

useDynamicScript

Build Status Size Dependencies

⚡ Dynamically import and remove script files in your React components.

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

Package Sidebar

Install

npm i usedynamicscript

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

8.46 kB

Total Files

14

Last publish

Collaborators

  • sekh