@andreyradkevichasap/use-script-loader-hook
v0.0.5
Published
I've created this hook, for making loading scripts easier. Hope it will save someone time. Below you can see how to use it.
Downloads
7
Maintainers
Readme
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>
};