Skip to content

Instantly share code, notes, and snippets.

@wilomgfx
Forked from BetterProgramming/useEffect.js
Created August 12, 2020 13:47
Show Gist options
  • Save wilomgfx/956863828e1305cba53ef7a69716a6dc to your computer and use it in GitHub Desktop.
Save wilomgfx/956863828e1305cba53ef7a69716a6dc to your computer and use it in GitHub Desktop.
import { useEffect } from 'react';
const importScript = resourceUrl=> {
useEffect(() => {
const script = document.createElement('script');
script.src = resourceUrl;
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
}
}, [resourceUrl]);
};
export default importScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment