-
-
Save designdevy/1e28e8d4710002c6dcebd1298b7cd99a to your computer and use it in GitHub Desktop.
This file contains 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 React, { useRef, useEffect } from 'react'; | |
const ExternalScript = ({ src }) => { | |
const ref = useRef(); | |
useEffect(() => { | |
const scriptEl = document.createElement("script"); | |
scriptEl.src = src; | |
ref.current.append(scriptEl); | |
}, [src]); | |
return <div ref={ref} />; | |
}; | |
const Hello = () => { | |
return ( | |
<div> | |
<h1>Hello, Medium</h1> | |
{/* This does work */} | |
<ExternalScript src="//google.com/somescript.js" /> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment