Skip to content

Instantly share code, notes, and snippets.

@ghankerson
Last active December 13, 2021 19:19
Show Gist options
  • Save ghankerson/339a9520531aa7be6cd4980c929a1a66 to your computer and use it in GitHub Desktop.
Save ghankerson/339a9520531aa7be6cd4980c929a1a66 to your computer and use it in GitHub Desktop.
Abbreviated NextJS/React Viafoura Implementation loadScript
const loadScript = function(id, src, callback) {
const existingScript = document.getElementById(id);
if (!existingScript) {
const script = document.createElement('script');
script.src = src;
script.id = id;
document.body.appendChild(script);
script.onload = () => {
if (callback) callback();
};
}
if (existingScript && callback) callback();
}
export default loadScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment