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

@pokactx/react-cliptext

v1.0.0

Published

Modern TypeScript React component and hook for copying text to clipboard with React 19 support

Readme

React ClipText

npm version license

Lightweight React clipboard utilities for TypeScript projects.

This package provides:

  • CopyToClipboard — a wrapper component that triggers copy on click or keyboard interaction
  • useCopyToClipboard — a hook built on the modern Clipboard API with legacy fallback

Installation

npm install react-cliptext
yarn add react-cliptext
pnpm add react-cliptext
bun add react-cliptext

Quick Start

CopyToClipboard

Wrap any single element. The component handles onClick and keyboard events automatically.

import { CopyToClipboard } from "react-cliptext";

function App() {
  return (
    <CopyToClipboard
      text="Hello World!"
      onCopy={(text, result) => {
        console.log("Copied:", text, result);
      }}
    >
      <button type="button">Copy to clipboard</button>
    </CopyToClipboard>
  );
}

Custom elements with role="button" also get Enter and Space keyboard support:

<CopyToClipboard text="Hello World!">
  <div role="button" tabIndex={0}>
    Copy to clipboard
  </div>
</CopyToClipboard>

useCopyToClipboard

import { useCopyToClipboard } from "react-cliptext";

function App() {
  const [copiedText, copy] = useCopyToClipboard();

  return (
    <button
      type="button"
      onClick={async () => {
        await copy("Hello World!");
      }}
    >
      {copiedText ? `Copied: ${copiedText}` : "Copy text"}
    </button>
  );
}

API

CopyToClipboard Props

| Prop | Type | Description | | ----------- | ----------------------------------------- | ----------------------------------------------- | | text | string | Text to copy. | | children | ReactElement | A single React element used as the trigger. | | onCopy | (text: string, result: boolean) => void | Called after each copy attempt. | | options | CopyToClipboardOptions | Forwarded to copy-to-clipboard. | | onClick | (event: MouseEvent) => void | Additional click handler merged with child's. | | onKeyDown | (event: KeyboardEvent) => void | Additional keydown handler merged with child's. |

Also accepts any React.HTMLAttributes<HTMLElement> (except onCopy, onClick, onKeyDown).

CopyToClipboardOptions

| Option | Type | Description | | --------- | --------- | ---------------------------------------------------------- | | debug | boolean | Enable debug logging. | | message | string | Custom message for the clipboard prompt (legacy browsers). | | format | string | MIME type for the clipboard data (e.g. "text/plain"). |

useCopyToClipboard

const [copiedText, copy] = useCopyToClipboard();
//     ^string|null  ^(text: string) => Promise<boolean>

| Return value | Type | Description | | ------------ | ------------------------------------ | ------------------------------------------------------------------------ | | copiedText | string \| null | Last successfully copied text, or null if nothing has been copied yet. | | copy | (text: string) => Promise<boolean> | Copies text and resolves true on success, false on failure. |

Behavior Notes

  • Native <button> elements use browser-default keyboard-to-click behavior.
  • Custom elements with role="button" trigger copy on Enter and Space.
  • Child onClick and onKeyDown handlers are preserved and called after the copy.
  • className props from the wrapper and child element are merged automatically.
  • The hook prefers navigator.clipboard.writeText() and falls back to copy-to-clipboard when the Clipboard API is unavailable.

Compatibility

  • React >=18 (React 19 fully supported)
  • TypeScript types included
  • ESM and CJS exports

License

MIT