React Tweet Embeds

3.3.0 · active · verified Sun Apr 19

react-tweet is a library maintained by Vercel that enables seamless embedding of individual tweets into React applications, supporting various build tools like Next.js and Vite. It provides components for rendering tweets, including media, and utilities for fetching tweet data. The current stable version is 3.3.0. The package maintains an active release cadence, frequently pushing minor updates and bug fixes, often in response to changes in the underlying X (formerly Twitter) platform's API or styling. Key differentiators include its tight integration with the Vercel ecosystem, built-in styling for a consistent look, and a focus on providing a reliable way to display tweet content that often faces challenges due to Twitter's evolving API access and rate limits.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates fetching a tweet using `getTweet` and rendering it with the `Tweet` component, suitable for SSR/SSG contexts.

import { Tweet } from 'react-tweet/components';
import { getTweet } from 'react-tweet/api';

// This component is designed for server-side fetching (e.g., Next.js Server Components)
// or client-side fetching with appropriate state management.
async function MyTweetEmbed({ id }: { id: string }) {
  const tweet = await getTweet(id);

  if (!tweet) {
    return <p>Tweet not found or private.</p>;
  }

  return (
    <div style={{
      display: 'flex',
      justifyContent: 'center',
      width: '100%',
      margin: '20px 0'
    }}>
      <Tweet rawTweet={tweet} />
    </div>
  );
}

// Example usage in a React component:
// <MyTweetEmbed id="1713028308833912089" />
// Remember to call `getTweet` in a server component or `useEffect` for client components.

view raw JSON →