Skip to content

Instantly share code, notes, and snippets.

@youngnishant
Last active February 19, 2022 06:13
Show Gist options
  • Select an option

  • Save youngnishant/f32e62b414d27f928d85885999c8e2f8 to your computer and use it in GitHub Desktop.

Select an option

Save youngnishant/f32e62b414d27f928d85885999c8e2f8 to your computer and use it in GitHub Desktop.
Load external script in react js or next js
const loadScript = src =>
new Promise(resolve => {
const script = document.createElement("script");
script.src = src;
script.onload = () => {
resolve(true);
};
script.onerror = () => {
resolve(false);
};
document.body.appendChild(script);
});
export default loadScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment