React Twitter Embed Components

4.0.4 · active · verified Sun Apr 19

react-twitter-embed is a JavaScript library providing a straightforward way to integrate various Twitter widgets (such as timelines, individual tweets, share buttons, follow buttons, and video embeds) into React applications. It acts as a wrapper around the official Twitter Widgets API, handling the asynchronous loading and rendering of Twitter's external scripts. The current stable version is 4.0.4. While release cadence isn't strictly predictable, the project has seen consistent updates addressing issues, adding new widget types, and ensuring compatibility with newer React versions. Its key differentiator is simplicity, abstracting away the complexities of the Twitter Widgets JavaScript API into declarative React components, making it easier to embed dynamic Twitter content without manual script management.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates embedding a Twitter timeline, a specific tweet, a share button, and a follow button in a React application using the core components provided by `react-twitter-embed`.

import React from 'react';
import ReactDOM from 'react-dom/client';
import { 
  TwitterTimelineEmbed, 
  TwitterTweetEmbed, 
  TwitterShareButton, 
  TwitterFollowButton 
} from 'react-twitter-embed';

function App() {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: '20px', padding: '20px' }}>
      <h1>My Twitter Embeds</h1>

      <h2>Recent Tweets (Timeline)</h2>
      <TwitterTimelineEmbed
        sourceType="profile"
        screenName="reactjs"
        options={{ height: 400 }}
      />

      <h2>Featured Tweet</h2>
      <TwitterTweetEmbed
        tweetId={'1567341851213031424'} // Example tweet ID for ReactJS
      />

      <h2>Share on Twitter</h2>
      <TwitterShareButton
        url={'https://react.dev'}
        options={{ text: 'Check out the new React docs!', via: 'reactjs' }}
      />

      <h2>Follow ReactJS</h2>
      <TwitterFollowButton
        screenName={'reactjs'}
      />
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

view raw JSON →