E
x
p
l
o
r
e
T
w
e
e
t
s
Installation
pnpm add react-tweet
pnpm add react-tweet
Installation React Server Component (Next.js 13+):
Copy and paste the following code into your project.
components/eldoraui/tweetgrid.tsx
"use client";
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { Tweet } from "react-tweet";
import { cn } from "@/lib/utils";
const tweetGridVariants = cva("max-w-4xl px-2 md:max-w-6xl", {
variants: {
columns: {
1: "columns-1",
2: "sm:columns-2",
3: "md:columns-3",
4: "lg:columns-4",
5: "xl:columns-5",
},
},
defaultVariants: {
columns: 3,
},
});
const tweetItemVariants = cva("break-inside-avoid", {
variants: {
spacing: {
sm: "mb-2",
md: "mb-4",
lg: "mb-6",
},
},
defaultVariants: {
spacing: "md",
},
});
export interface TweetGridProps
extends VariantProps<typeof tweetGridVariants>,
VariantProps<typeof tweetItemVariants> {
tweets: string[];
className?: string;
}
export const TweetGrid: React.FC<TweetGridProps> = ({
tweets,
columns,
spacing,
className,
}) => {
return (
<div className={cn(tweetGridVariants({ columns }), className)}>
{tweets.map((tweetId, i) => (
<div
key={`${tweetId}-${i}`}
className={cn(tweetItemVariants({ spacing }))}
>
<Tweet id={tweetId} />
</div>
))}
</div>
);
};
Update the import paths to match your project setup.
Props
TweetGrid
Component Props
Prop Name | Type | Default | Description |
---|---|---|---|
tweets | string[] | - | An array of tweet IDs (as strings) to display in the grid. |
columns | 1|2|3|4|5 | 3 | The number of columns in the grid. For values: 1 , 2 , 3 , 4 , or 5 . |
spacing | sm|md|lg | md | The spacing between tweet items. For values: sm , md , or lg . |
className | string | undefined | An optional custom className for further styling of the grid container. |