Last active
December 13, 2021 19:19
-
-
Save ghankerson/339a9520531aa7be6cd4980c929a1a66 to your computer and use it in GitHub Desktop.
Abbreviated NextJS/React Viafoura Implementation loadScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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