You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Log when a tweet does not exist or if it's private (#133)
* Log when a tweet does not exist or if it's private
* Added caching
* Updated deps
* Updated docs
* Updated docs more
* Added changeset
* Updated deps
* Updated link
Copy file name to clipboardExpand all lines: apps/site/pages/api-reference.mdx
+19
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,25 @@ Fetches and returns a [`Tweet`](https://github.com/vercel-labs/react-tweet/blob/
20
20
21
21
Ifatweetisnotfounditreturns`undefined`.
22
22
23
+
## `fetchTweet`
24
+
25
+
```tsx
26
+
function fetchTweet(
27
+
id: string,
28
+
fetchOptions?: RequestInit
29
+
): Promise<{
30
+
data?: Tweet | undefined
31
+
tombstone?: true | undefined
32
+
notFound?: true | undefined
33
+
}>
34
+
```
35
+
36
+
Fetchesandreturnsa [`Tweet`](https://github.com/vercel-labs/react-tweet/blob/main/packages/react-tweet/src/api/types/tweet.ts) just like [`getTweet`](#gettweet), but it also returns additional information about the tweet:
Copy file name to clipboardExpand all lines: apps/site/pages/index.mdx
+60
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ Now follow the usage instructions for your framework or builder:
28
28
-[Vite](/vite)
29
29
-[Create React App](/create-react-app)
30
30
31
+
> **Important**: Before going to production, we recommend [enabling cache for the Twitter API](#enabling-cache-for-the-twitter-api) as server IPs might get rate limited by Twitter.
32
+
31
33
## Choosing a theme
32
34
33
35
The [`prefers-color-scheme`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) CSS media feature is used to select the theme of the tweet.
@@ -61,3 +63,61 @@ In CSS Modules, you can use the `:global` selector to update the CSS variables u
61
63
```
62
64
63
65
For Global CSS the usage of `:global` is not necessary.
66
+
67
+
## Enabling cache for the Twitter API
68
+
69
+
Rendering tweets requires making a call to Twitter's syndication API. Getting rate limited by that API is very hard but it's possible if you're relying only on the endpoint we provide for SWR (`react-tweet.vercel.app/api/tweet/:id`) as the IPs of the server are making many requests to the syndication API. This also applies to RSC where the API endpoint is not required but the server is still making the request from the same IP.
70
+
71
+
To prevent this, you can use a db like Redis or [Vercel KV](https://vercel.com/docs/storage/vercel-kv) to cache the tweets. For example using [Vercel KV](https://vercel.com/docs/storage/vercel-kv):
You can see it working at [react-tweet-next.vercel.app/light/vercel-kv/1629307668568633344](https://react-tweet-next.vercel.app/light/vercel-kv/1629307668568633344) ([source](https://github.com/vercel/react-tweet/blob/main/apps/next-app/app/light/vercel-kv/%5Btweet%5D/page.tsx)).
122
+
123
+
If you're using Next.js then using [`unstable_cache`](/next#enabling-cache) works too.
0 commit comments