Skip to content

PandaSekh/React-useDynamicScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

⚡ Dynamically import and remove script files in React components.

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •