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.
npm install react-tweetVerified import paths — ran on the pinned version, not inferred.
Demonstrates fetching a tweet using `getTweet` and rendering it with the `Tweet` component, suitable for SSR/SSG contexts.
Update import statements: `import { Tweet } from 'react-tweet/components';` and `import { getTweet } from 'react-tweet/api';`.Ensure you are importing the base styles, for example, by adding `import 'react-tweet/styles';` to your root layout or entry file.
No direct fix needed, but be aware of the change in rendering context for the time component. If custom date formatting is required on the client, you'll need to implement it yourself.
Always check if the result of `getTweet` is `undefined` before attempting to render the `Tweet` component. For example: `const tweet = await getTweet(id); if (!tweet) return <TweetNotFound />;`
Ensure your project uses React 18 or React 19 to satisfy peer dependency requirements and avoid potential warnings or issues.
Change `import { Tweet } from 'react-tweet';` to `import { Tweet } from 'react-tweet/components';` or `import { getTweet } from 'react-tweet/api';`.If `Tweet` is a Server Component, the `key` prop should be applied to the parent element if mapping over a list, not directly to `Tweet` itself.
Always verify that `getTweet` returns a valid tweet object before passing it to the `Tweet` component. Add checks like `if (!tweet) return null;`.
Update to `react-tweet@3.1.0` or newer. Ensure styles are correctly imported, as `react-tweet/styles` provides the necessary icons.