diff --git a/src/components/embeds/Twitter.jsx b/src/components/embeds/Twitter.jsx new file mode 100644 index 00000000..90f8a684 --- /dev/null +++ b/src/components/embeds/Twitter.jsx @@ -0,0 +1,46 @@ +import React, { useState, useEffect } from 'react'; + +const Twitter = ({ url }) => { + const [embedCode, setEmbedCode] = useState(null); + + useEffect(async () => { + const prot = window.location.protocol.startsWith('http') + ? window.location.protocol : 'https'; + // eslint-disable-next-line max-len + const tkurl = `${prot}//publish.twitter.com/oembed?url=${encodeURIComponent(url)}`; + const resp = await fetch(tkurl); + const embedData = await resp.json(); + if (embedData.html) { + setEmbedCode(embedData.html); + } + }, []); + + if (!embedCode) { + return
LOADING
; + } + + return ( +