import { Box } from "@mui/material"; import { FacebookEmbed, InstagramEmbed, TwitterEmbed } from "react-social-media-embed"; import { regex } from "../../../lib/regex"; import { useWidth } from "../../ContextProvider"; export default function SocialMediaEmbed(props: { url: string }) { const { url } = props; const [width] = useWidth(); const Element = [ { element: , regex: regex.instagram, }, { element: ( ), regex: regex.facebook.posts, }, { element: ( ), regex: regex.twitter, }, ].find((item) => item.regex.some((regex) => url.match(regex)))?.element; if (!Element) return null; return {Element}; }