justinmahar / react-social-media-embed

📰 Easily embed social media posts from Facebook, Instagram, LinkedIn, Pinterest, TikTok, X (Twitter), and YouTube in React.
https://justinmahar.github.io/react-social-media-embed/
MIT License
228 stars 30 forks source link

Might have figured out how to manually set up Tiktok embed! #74

Open marincarroll opened 7 months ago

marincarroll commented 7 months ago

Hey there, I saw you were looking for a way to manually initialize the embed HTML – I'm doing something kinda different so I'm not sure this is applicable to your specific situation but it's worth a try! This works for me:

1) find the element you want to embed (blockquote with class tiktok-embed); 2) pass it to tiktokEmbed.lib.render() INSIDE AN ARRAY (looking at the render function in the compiled embed script it was hard to tell what was going on but it looks like it scans the entire document for tiktok embeds and goes through them one by one, so I tried just passing an array with the one element I wanted to embed, and it worked!)

const tiktok = document.querySelector( '.tiktok-embed' );
    if( tiktok ) {
        tiktokEmbed.lib.render( [ tiktok ] );
    }
}
justinmahar commented 6 months ago

You're awesome, @marincarroll! I'll have a look into adding this when I get some free time. Thanks!