Last active
February 19, 2022 06:13
-
-
Save youngnishant/f32e62b414d27f928d85885999c8e2f8 to your computer and use it in GitHub Desktop.
Load external script in react js or next js
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 = 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