Skip to content

Instantly share code, notes, and snippets.

@jakejrichards
Last active August 3, 2020 06:04
Show Gist options
  • Save jakejrichards/2ce843ff4dcf03977ef41690a08cf1e3 to your computer and use it in GitHub Desktop.
Save jakejrichards/2ce843ff4dcf03977ef41690a08cf1e3 to your computer and use it in GitHub Desktop.
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