Client Tweet Card

PreviousNext

A client-side version of the tweet card that displays a tweet with the author's name, handle, and profile picture.

Docs
magicuiui

Preview

Loading preview…
registry/magicui/client-tweet-card.tsx
"use client"

import { TweetProps, useTweet } from "react-tweet"

import {
  MagicTweet,
  TweetNotFound,
  TweetSkeleton,
} from "@/registry/magicui/tweet-card"

export const ClientTweetCard = ({
  id,
  apiUrl,
  fallback = <TweetSkeleton />,
  components,
  fetchOptions,
  onError,
  ...props
}: TweetProps & { className?: string }) => {
  const { data, error, isLoading } = useTweet(id, apiUrl, fetchOptions)

  if (isLoading) return fallback
  if (error || !data) {
    const NotFound = components?.TweetNotFound || TweetNotFound
    return <NotFound error={onError ? onError(error) : error} />
  }

  return <MagicTweet tweet={data} {...props} />
}

Installation

npx shadcn@latest add @magicui/client-tweet-card

Usage

import { ClientTweetCard } from "@/components/ui/client-tweet-card"
<ClientTweetCard />