Created
April 7, 2020 23:58
-
-
Save BetterProgramming/320d5b74494f37fd544000ef193f1523 to your computer and use it in GitHub Desktop.
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
| 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