Blog Articles

Information Technology

Embed Social Media widgets in React

blog image

Embed Social Media widgets in React

Learn how to seamlessly embed social media widgets into your React app for enhanced user engagement and interactivity. Get started now!

Embed Social Media widgets in React
Sahil Khurana
Published: February 19, 2024

Key takeaways

  1. The addition of Social media widgets into a React-based Application increases User engagement, by using most of the social platforms such as Twitter, Facebook, Instagram, LinkedIn and YouTube, makes the content more dynamic.

  2. Employ the unique codes or APIs issued by the social media platforms to develop React components for each widget and control them using such packages as react-social-media-embed.

  3. Start by using create-react-app to create your React app and Bootstrap to style the app, before using the social media widgets to expand the app’s features and improve the user experience, and to make it easy to integrate the code.

Embedding these social media widgets within your React app enhances the user’s interaction; user engagement, therefore, is highly enacted with its app by fluently rolling the most trendy social media platforms. Of course, building dynamic interfaces around social in-app, or inclusive social media widgets within the app, is an excellent choice to speed up web development in the React.js library.

To embed social media widgets in a React app, you can follow these general steps:

  1. Choose The Social Media Platforms: The very next thing is to pick the right social media platforms. The major ones will involve the likes of Twitter, Facebook, Instagram, LinkedIn, and Google, among others.
  2. Select the appropriate Embed Code: Usually, each of the social media platforms usually gives an embed code or API that you can use to embed content from them right into your web application. You can obtain this by following documentation they always provide in regard to developers found therein.
  3. Create Components: Define React Components: Create React components of each social media widget that the application needs to include in order to encapsulate them. Such components will contain the JSX of the embed code of the actual content.

Create a React App

  1. Use npx command to create a react app Open terminal and give this command npx create-react-app social-media-widgets-react-app
  2. After creating the react app, then you need to change the directory using the cd command like:
    cd social-media-widgets-react-app 
  3. You can start the react app using the command:
    npm  start
  4. App will be running on a local host and you can see the default content of the react app. 
  5. For styling you can use the bootstrap and install using the NPM package:
    npm  i bootstrap react-bootstrap 

Inject the social media widget in React App

  1. Now using an NPM package, we can inject the social media widget in the react app. Now give this command your react app.
    npm i react-social-media-embed
  2. Create a custom component to keep all widgets into that.
  3. Now you can follow these snippets to use the social media widgets in the App.  

Facebook – social media widget for React

You can import the FacebookEmbed and pass the URL of the post and styling of the widget.

react social media facebook

Instagram

You can import the InstagramEmbed and pass the URL of the post and styling of the widget

react social media instagram

LinkedIn

You can import the LinkedIn Embed and pass the URL of the post and styling of the widget.

react social media linkedin

X (Twitter)

You can import the XEmbed for Twitter and pass the URL of the post and styling of the widget.

react social media twitter

Youtube

You can import the YoutubeEmbed for Youtube and pass the URL of the post and styling of the widget.

Sign Up Now
Get a Fast Estimate on Your Software Development Project

We are committed to delivering high-quality IT solutions tailored to meet the unique needs of our clients. As part of our commitment to transparency and excellence, we provide detailed project estimations to help our clients understand the scope, timeline, and budget associated with their IT initiatives.