Skip to content

t0yohei/react-copy-to-clipboard-ts

Repository files navigation

react-copy-to-clipboard-ts

This package is a fork of react-copy-to-clipboard. The main differences are:

  • React 18, 19 compatibility
  • TypeScript support
  • ESM and CommonJS support
  • Zero dependencies (except copy-to-clipboard)
  • Simple and lightweight

Installation

npm install react-copy-to-clipboard-ts
# or
yarn add react-copy-to-clipboard-ts

Usage

// Named import (recommended)
import { CopyToClipboard } from "react-copy-to-clipboard-ts";

// Default import (for migration from react-copy-to-clipboard)
import CopyToClipboard from "react-copy-to-clipboard-ts";

function App() {
  return (
    <CopyToClipboard text="Text to copy">
      <button type="button">Copy to clipboard</button>
    </CopyToClipboard>
  );
}

Props

Prop Type Description
text string Text to copy to clipboard
onCopy (text: string, result: boolean) => void Callback function that will be called when text is copied

Simple web demo

https://t0yohei.github.io/react-copy-to-clipboard-ts/

Development

# Install dependencies
yarn install

# Run tests
yarn test

# Run linting
yarn lint

# Format code
yarn format

# Build
yarn build

# Run demo
yarn demo:dev

License

MIT

About

React 18, 19 compatible copy-to-clipboard component with TypeScript

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •