Skip to content

Instantly share code, notes, and snippets.

@designdevy
Forked from jakejrichards/correct.jsx
Created August 3, 2020 06:04
Show Gist options
  • Save designdevy/1e28e8d4710002c6dcebd1298b7cd99a to your computer and use it in GitHub Desktop.
Save designdevy/1e28e8d4710002c6dcebd1298b7cd99a 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