0.0.5 • Published 3 years ago

@andreyradkevichasap/use-script-loader-hook v0.0.5

Weekly downloads
20
License
-
Repository
-
Last release
3 years ago

I've created this hook, for making loading scripts easier. Hope it will save someone time. Below you can see how to use it.

import useScriptLoader from "@andreyradkevichasap/use-script-loader-hook";

const YourComponent = () => {
  const { load } = useScriptLoader();

  const onLoad = useCallback(() => {
    load({
      src: "script_url",
      globalName: "window[globalName]" // for example zendesk attach $zopim to window object, then globalName="$zopim"
    }).then(data => {
      // data = window[globalName]
    });
  }, [load]);

  return <div>
    <button onClick={onLoad}>Load Script</button>
  <div>
};
0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago