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

great-react-screenshot

v0.0.1

Published

React hook to take screenshot of components - Easy way to capture screenshots of React components and DOM elements. Perfect for taking screenshots in React apps with TypeScript support.

Readme

great-react-screenshot

A simple and powerful React hook for taking screenshots of React components and DOM elements. Perfect solution for how to take screenshot in React. Built on top of html-to-image, this hook provides a clean API for capturing screenshots of any React component or DOM element.

Installation

npm install great-react-screenshot
# or
pnpm add great-react-screenshot
# or
yarn add great-react-screenshot

Quick Start

import { useScreenshot } from "great-react-screenshot";

function App() {
  const { parentRef, takeScreenshot, image, isCapturing } = useScreenshot();

  const handleCapture = async () => {
    const dataUrl = await takeScreenshot();
  };

  return (
    <div>
      <div ref={parentRef} style={{ padding: "20px", background: "#f0f0f0" }}>
        <h1>This will be captured!</h1>
        <p>Click the button below to take a screenshot.</p>
      </div>
      <button onClick={handleCapture} disabled={isCapturing}>
        {isCapturing ? "Capturing..." : "Take Screenshot"}
      </button>
      {image && <img src={image} alt="Screenshot" />}
    </div>
  );
}

API

useScreenshot(options?)

Returns an object with the following properties:

Return Value

| Property | Type | Description | | ---------------- | ------------------------------------------------- | ------------------------------------------------ | | parentRef | React.RefObject<T> | Ref to attach to the element you want to capture | | status | "idle" \| "capturing" \| "completed" \| "error" | Current status of the screenshot operation | | isCapturing | boolean | Shorthand for status === "capturing" | | isCompleted | boolean | Shorthand for status === "completed" | | error | Error \| null | Error object if capture failed | | image | string \| null | Base64 data URL of the captured image | | takeScreenshot | () => Promise<string \| null> | Function to trigger the screenshot | | reset | () => void | Reset the hook state to initial values |

Options

| Option | Type | Default | Description | | ----------------- | ----------------- | ----------- | -------------------------------------------------- | | quality | number | 1 | Image quality (0-1), only applies to JPEG format | | format | "png" \| "jpeg" | "png" | Output image format | | backgroundColor | string | undefined | Background color for the image (e.g., "#ffffff") |

Examples

Basic Usage

import { useScreenshot } from "great-react-screenshot";

function Card() {
  const { parentRef, takeScreenshot, image } = useScreenshot();

  return (
    <div>
      <div ref={parentRef} className="card">
        <h2>My Card</h2>
        <p>Card content here</p>
      </div>
      <button onClick={takeScreenshot}>Capture</button>
      {image && <img src={image} alt="Captured" />}
    </div>
  );
}

With Custom Options

import { useScreenshot } from "great-react-screenshot";

function App() {
  const { parentRef, takeScreenshot, image } = useScreenshot({
    format: "jpeg",
    quality: 0.8,
    backgroundColor: "#ffffff",
  });

  return (
    <div>
      <div ref={parentRef}>
        <h1>Content to capture</h1>
      </div>
      <button onClick={takeScreenshot}>Take JPEG Screenshot</button>
      {image && <img src={image} alt="Screenshot" />}
    </div>
  );
}

Download Screenshot

import { useScreenshot } from "great-react-screenshot";

function DownloadableCard() {
  const { parentRef, takeScreenshot, isCapturing } = useScreenshot();

  const handleDownload = async () => {
    const dataUrl = await takeScreenshot();
    if (dataUrl) {
      const link = document.createElement("a");
      link.download = "screenshot.png";
      link.href = dataUrl;
      link.click();
    }
  };

  return (
    <div>
      <div ref={parentRef} className="card">
        <h2>Downloadable Card</h2>
      </div>
      <button onClick={handleDownload} disabled={isCapturing}>
        {isCapturing ? "Capturing..." : "Download Screenshot"}
      </button>
    </div>
  );
}

Error Handling

import { useScreenshot } from "great-react-screenshot";

function App() {
  const { parentRef, takeScreenshot, error, status } = useScreenshot();

  const handleCapture = async () => {
    await takeScreenshot();
  };

  return (
    <div>
      <div ref={parentRef}>
        <h1>Content</h1>
      </div>
      <button onClick={handleCapture}>Capture</button>
      {error && <p style={{ color: "red" }}>Error: {error.message}</p>}
      {status === "completed" && <p>✓ Screenshot captured!</p>}
    </div>
  );
}

Reset State

import { useScreenshot } from "great-react-screenshot";

function App() {
  const { parentRef, takeScreenshot, image, reset } = useScreenshot();

  return (
    <div>
      <div ref={parentRef}>
        <h1>Content</h1>
      </div>
      <button onClick={takeScreenshot}>Capture</button>
      <button onClick={reset}>Reset</button>
      {image && <img src={image} alt="Screenshot" />}
    </div>
  );
}

TypeScript with Custom Element Type

import { useScreenshot } from "great-react-screenshot";

function App() {
  const { parentRef, takeScreenshot } = useScreenshot<HTMLCanvasElement>();

  return (
    <div>
      <canvas ref={parentRef} width={400} height={300} />
      <button onClick={takeScreenshot}>Capture Canvas</button>
    </div>
  );
}

License

ISC