leerob wanted a page for saving favorite tweets, but the usual embed approach loads each tweet in an iframe and was slow when the page had several. He set out to fetch tweet data through Twitter’s API and generate the page statically.
Rebuilding the Twitter Embed Widget!
leerob, a software developer, explains how he rebuilt Twitter embeds with Next.js and Tailwind CSS for a faster tweets page on his website.
He first mocked up a streamlined tweet in Tailwind Play, then reviewed Twitter’s v2 API requirements, including a developer account, project, app, and API token. His `getTweets` function requests tweet fields and related data such as media and referenced authors, using a bearer token for authentication.
A Next.js API route let him inspect the raw response, where media and users arrived as separate objects. Helper functions join media keys to media objects and author IDs to user details, while `reduce` builds a top-level array of enriched tweets.
The `/tweets` page uses `getStaticProps` to fetch tweet IDs and pass the results into a React component. The component fills in author details, verification status, images, formatted text, metrics, and dates; it also calls itself to display quote tweets. The 171-line component handles text, images, and quote tweets, while video, GIF, and reply support remain possible additions.
Takeaways
- Replace third-party embeds with API data and static generation when iframe loading slows a content page.
- Normalize related API objects into a UI-ready shape before passing data to components.
- Start with a static design mockup, then make its content dynamic from real API responses.
- Recursive components can render nested quote tweets without a separate rendering path.
- Define a clear first version: this implementation covers text, images, and quote tweets, with other media types left for later.
Mentioned in this talk
Search inside this talk
What was claimed 6
- integrates withReact Twitter Embed integrates with
Twitter
“It puts an iframe on your page”
YouTube Unverified1 source· Talk
- featureAnthropic API: The v2 endpoint can fetch multiple tweets and associated fields
“The endpoint we care about fetches multiple tweets”
YouTube Unverified1 source· Talk
- feature
Next.js: GetStaticProps enables fetching tweet data for static page generation
“We use that to pass in an array of different tweet IDs”
YouTube Unverified1 source· Talk
- feature
Next.js: Next/image handles responsiveness, aspect ratio, and image optimization
“next/image, which handles responsiveness, aspect ratio, and image optimization”
YouTube Unverified1 source· Talk
- featureTailwind CSS: Tailwind 2.0 supports dark mode
“using Tailwind CSS—specifically Tailwind 2.0—I also have support for dark mode”
YouTube Unverified1 source· Talk
- featureRecursive component: Renders a quoted tweet nested below the tweet being highlighted
“if there is a quote tweet, we're actually going to have this component call itself”
YouTube Unverified1 source· Talk
Related talks
12:33
1:21:37
50:44
1:57:48
9:28
6:35