Last active
August 3, 2020 06:04
-
-
Save jakejrichards/2ce843ff4dcf03977ef41690a08cf1e3 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