Created
June 30, 2020 14:18
-
-
Save hperantunes/664270797c6c0928c60f0728da09b1a5 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 useScript = (url) => { | |
useEffect(() => { | |
const script = document.createElement("script"); | |
script.src = url; | |
script.async = true; | |
document.body.appendChild(script); | |
return () => { | |
document.body.removeChild(script); | |
}; | |
}, [url]); | |
}; | |
export default useScript; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment