npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-og-preview

v0.2.0

Published

React component to preview Open Graph social media cards

Downloads

487

Readme

react-og-preview

npm version license

A library of pixel-perfect React components for previewing Open Graph links shared to social media platforms.

Live Demo

Supported Platforms

  • Twitter/X — both compact and large variants
  • Facebook
  • LinkedIn
  • Slack
  • Discord
  • more soon...

Installation

pnpm install react-og-preview

Setup

Import the styles once in your app's entry point:

import "react-og-preview/styles.css";

Quick Start

import { SocialPreview } from "react-og-preview";

function App() {
  return (
    <SocialPreview
      provider="twitter"
      variant="large"
      url="https://example.com/article"
      title="Amazing Article Title"
      description="This is a preview of what your link will look like when shared."
      image="https://example.com/og-image.jpg"
    />
  );
}

API Reference

<SocialPreview />

The main component that renders a preview card for the specified social platform.

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | provider | "twitter" | "facebook" | "linkedin" | "slack" | "discord" | — | Required. The social platform to preview. | | url | string | — | Required. The canonical URL being previewed. | | title | string \| null | — | Required. The page title (og:title). | | description | string \| null | — | Optional description text (og:description). | | image | string \| ImageMetadata \| null | — | Image URL or metadata object (og:image). | | video | string \| VideoMetadata \| null | — | Video URL or metadata object (og:video). | | audio | string \| AudioMetadata \| null | — | Audio URL or metadata object (og:audio). | | variant | "compact" | "large" | "large" | Twitter only. Card style (summary vs summary_large_image). | | className | string | — | Additional CSS classes for the card container. | | disableLink | boolean | false | Renders without an anchor wrapper for non-interactive use. | | ImageComponent | React.ComponentType | — | Custom component for rendering images. | | VideoComponent | React.ComponentType | — | Custom component for rendering videos. | | AudioComponent | React.ComponentType | — | Custom component for rendering audio. |

Metadata Types

For structured Open Graph metadata, you can pass objects instead of URL strings:

interface ImageMetadata {
  url: string;
  secureUrl?: string;
  type?: string;      // e.g., "image/jpeg"
  width?: number;
  height?: number;
  alt?: string;
}

interface VideoMetadata {
  url: string;
  secureUrl?: string;
  type?: string;      // e.g., "video/mp4"
  width?: number;
  height?: number;
}

interface AudioMetadata {
  url: string;
  secureUrl?: string;
  type?: string;      // e.g., "audio/mpeg"
}

Dark Mode

Add a dark class to any parent element to enable dark mode styles:

<div className="dark">
  <SocialPreview provider="twitter" ... />
</div>

Custom Components

Custom Image Component

Integrate with image optimization libraries like Next.js Image:

import Image from "next/image";
import { SocialPreview } from "react-og-preview";

<SocialPreview
  provider="facebook"
  url="https://example.com"
  title="My Article"
  ImageComponent={({ src, alt, width, height, className, onError }) => (
    <Image
      src={src}
      alt={alt}
      width={width ?? 1200}
      height={height ?? 630}
      className={className}
      onError={onError}
    />
  )}
/>

Custom Video Component

Replace the default react-player with your own video player:

<SocialPreview
  provider="discord"
  url="https://example.com"
  title="Video Post"
  video="https://example.com/video.mp4"
  VideoComponent={({ src, poster, controls, className }) => (
    <video
      src={src}
      poster={poster}
      controls={controls}
      className={className}
    />
  )}
/>

Custom Audio Component

<SocialPreview
  provider="slack"
  url="https://example.com"
  title="Podcast Episode"
  audio="https://example.com/episode.mp3"
  AudioComponent={({ src, controls, className }) => (
    <audio src={src} controls={controls} className={className} />
  )}
/>

Individual Provider Components

For better tree-shaking, import individual provider cards directly:

import {
  TwitterCard,
  FacebookCard,
  LinkedInCard,
  SlackCard,
  DiscordCard,
} from "react-og-preview";

<TwitterCard
  url="https://example.com"
  title="My Tweet"
  variant="large"
/>

License

MIT