I have a list where I'm displaying media links as iframes using Embed component.
Normally in my input, any pasted link will generate a specific iframe, meaning youtube has it iframe, twitter etc..
My question, is there a way to display or save the name of the website of the written url in title ?
So for example when pasting a Twitch link, the title will be Twitch. As far as I know "Embed" do something like this to detect the link and give it the appropriate iframe.
https://codesandbox.io/s/suspicious-cherry-ngv0h?file=/src/App.js
import React, { useState } from "react";
import Embed from "react-embed";
export default () => {
const reactList = [
{
id: "2",
title: "Twitter",
media: "https://twitter.com/Betclic/status/1382074820628783116?s=20"
}
];
const [links, setLinks] = useState(reactList);
const [media, setMedia] = React.useState("");
function handleChange(event) {
setMedia(event.target.value);
}
function handleAdd() {
const newList = links.concat({ media });
setLinks(newList);
}
return (
<div>
<div>
<input type="text" value={media} onChange={handleChange} />
<button type="button" onClick={handleAdd}>
Add
</button>
</div>
<ul>
<div style={{ width: "50vh" }}>
{links.reverse().map((url, indexurl) => (
<li key={url.id}>
<div>{url.title}</div>
<Embed url={url.media} />
</li>
))}
</div>
</ul>
</div>
);
};