react-copy-to-clipboard-ts
Version:
React 18, 19 compatible copy-to-clipboard component with TypeScript
73 lines (51 loc) • 1.55 kB
Markdown
This package is a fork of [react-copy-to-clipboard](https://github.com/nkbt/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
```bash
npm install react-copy-to-clipboard-ts
# or
yarn add react-copy-to-clipboard-ts
```
## Usage
```tsx
// 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>
);
}
```
| 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 |
https://t0yohei.github.io/react-copy-to-clipboard-ts/
```bash
yarn install
yarn test
yarn lint
yarn format
yarn build
yarn demo:dev
```
MIT