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-copy-to-clipboard-lite

v1.0.3

Published

Tiny, modern React 19+ clipboard utility with tiered fallback and metadata.

Readme

react-copy-to-clipboard-lite

Tiny(~1.1 kB), dependency-free clipboard utility for React 18+. SSR-safe. Permission-aware. MIT.

CI Size License


Why this library?

  • Zero runtime dependencies, tiered fallback (Clipboard API → execCommand)
  • Structured CopyResult, never throws
  • Permission-aware (no prompt()), SSR-safe
  • React 19 formAction / useActionState support
  • TypeScript strict, size-gated in CI, Unit + E2E coverage

Install

npm install react-copy-to-clipboard-lite
# or: pnpm add / yarn add

Peer: react >= 18


Demo

Live demo · Run locally: npm run dev:demo

Demo preview


Core (framework-agnostic)

import { copyToClipboard } from "react-copy-to-clipboard-lite";

const result = await copyToClipboard("Hello world");
if (result.success) console.log("Copied via:", result.method);
else console.log("Failed:", result.code);

Hook

import { useCopyToClipboard } from "react-copy-to-clipboard-lite/react";

function Example() {
  const { copy, copied, error } = useCopyToClipboard({ timeout: 1500, clearAfter: 1000 });
  return (
    <button onClick={() => copy("Secret API Key")}>{copied ? "Copied!" : "Copy"}</button>
  );
}

copy(text)Promise<CopyResult> · copied / error / reset()


Component

import { CopyToClipboard } from "react-copy-to-clipboard-lite/react";

<CopyToClipboard text="Copy this" onSuccess={() => {}} onError={(r) => console.log(r.code)}>
  <button>Copy</button>
</CopyToClipboard>

Preserves your onClick; works with buttons, spans, links.


React 19 Action

import { copyToClipboardAction } from "react-copy-to-clipboard-lite/react";

<form>
  <input name="text" defaultValue="Hello" />
  <button formAction={copyToClipboardAction}>Copy</button>
</form>

Works with useActionState and Server Components (client boundary).


CopyResult

type CopyResult = {
  success: boolean;
  method: "clipboard-api" | "exec-command" | "unsupported" | "failed";
  code?: "SECURITY_ERROR" | "PERMISSION_DENIED" | "INSECURE_CONTEXT" | "NO_BROWSER_SUPPORT" | "UNKNOWN";
  error?: unknown;
};

clearAfter (e.g. passwords)

copyToClipboard("my-password", { clearAfter: 3000 });

Clears clipboard after X ms (best-effort). Never reads clipboard.


Behaviour

  • Permission-aware: uses navigator.permissions.query() when available; never prompts.
  • SSR-safe: browser APIs used only inside functions. Works in Next.js, Remix, Vite SSR, Astro, RSC.
  • Size: CI enforces < 2 KB (index), < 3 KB (react); brotli.

Browser support

| Clipboard API | execCommand fallback | IE11 | |---------------|----------------------|------| | Modern | Safari / legacy | No |

No prompt() fallback; no clipboard-read.


Comparison

| Feature | This lib | Typical | |-------------------|----------|---------| | Zero deps | Yes | No | | SSR safe | Yes | Often | | Structured result | Yes | No | | React 19 Actions | Yes | No | | Permission-aware | Yes | No |


Migration from react-copy-to-clipboard

- import { CopyToClipboard } from "react-copy-to-clipboard"
+ import { CopyToClipboard } from "react-copy-to-clipboard-lite/react"

Contributing

PRs welcome. Before submitting: npm run test:all (typecheck, unit, Playwright, size).


License

MIT © Raju Dandigam