# react-clipboardjs-copy

> clipboard.js copy component for react

Latest version **2.1.0** (published 2024-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-clipboardjs-copy
pnpm add react-clipboardjs-copy
yarn add react-clipboardjs-copy
bun add react-clipboardjs-copy
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2024-10-29 |
| First published | 2018-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | ShineShao |
| Maintainers | freeshine |
| Keywords | react, react-component, clipboard, copy, cut, react-clipboardjs-copy |

## Links

- npm: https://www.npmjs.com/package/react-clipboardjs-copy
- Repository: https://github.com/freeshineit/react-clipboardjs-copy
- Homepage: https://freeshineit.github.io/react-clipboardjs-copy
- Issues: https://github.com/freeshineit/react-clipboardjs-copy/issues
- npm.io page: https://npm.io/package/react-clipboardjs-copy

## Dependencies (1)

- [clipboard](https://npm.io/package/clipboard.md) 2.0.11

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2024-10-29
- 3.0.0-beta.1 (beta) — 2026-04-19
- 2.1.0-beta.1 — 2024-10-29
- 2.0.2 — 2024-04-06
- 2.0.1 — 2024-04-06
- 2.0.1-alpha.0 — 2024-04-06
- 2.0.0 — 2022-10-02
- 2.0.0-alpha3 — 2022-10-02
- 2.0.0-alpha2 — 2022-10-02
- 2.0.0-alpha1 — 2022-10-02
- 1.3.2 — 2020-09-06
- 1.3.1 — 2019-07-02
- 1.3.0 — 2019-02-18
- 1.2.2 — 2018-12-26
- 1.2.1 — 2018-12-06
- … 7 more at https://npm.io/package/react-clipboardjs-copy/versions

## README

# react-clipboardjs-copy

![build](https://github.com/freeshineit/react-clipboardjs-copy/workflows/build/badge.svg) ![Download](https://img.shields.io/npm/dm/react-clipboardjs-copy.svg) ![Version](https://img.shields.io/npm/v/react-clipboardjs-copy.svg) ![License](https://img.shields.io/npm/l/react-clipboardjs-copy.svg)

A react copy component that based on `clipboard.js`

[中文](./README_zh-CN.md)

## Installing

```sh
npm install --save react-clipboardjs-copy
```

## Basic usage

```jsx
import React from 'react';
import ReactClipboard from 'react-clipboardjs-copy';
import './App.css';
export default class App extends React.Component {
  render() {
    return (
      <div className="App">
        <section className="app-item">
          <div className="app-item-desc">Copy text</div>
          <ReactClipboard text="copy text" onSuccess={() => {}} onError={() => {}}>
            <button
              onClick={() => {
                console.log('click button');
              }}
            >
              Copy Text
            </button>
          </ReactClipboard>
        </section>
        <section className="app-item">
          <div className="app-item-desc">
            <textarea id="textarea">Mussum ipsum cacilds...</textarea>
            <div />
          </div>
          <ReactClipboard action="cut" target="#textarea" onSuccess={() => {}} onError={() => {}}>
            <button>Cut</button>
          </ReactClipboard>
        </section>
      </div>
    );
  }
}
```

```jsx
<input id="input" value="git@github.com:freeshineit/react-clipboardjs-copy.git" />
<ReactClipboard
  target="#input"
  onSuccess={handleSuccess}
  onError={handleError}
>
  <button>
    Copy Input value
  </button>
</ReactClipboard>
```

## Options(props)

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| action | Overwrites default command (`cut` or `copy`) , Corresponding to clipboard.js attribute data-clipboard-action. | `cut` \| `copy` | `copy` |
| target | React component will copy target element content. Corresponding to `clipboard.js` attribute `data-clipboard-target`. | string \| function(elem: Element): Element | - |
| text | React component will copy content. Corresponding to `clipboard.js` attribute `data-clipboard-text` | string \| function(elem: Element): string |  |
| container | For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value. | Element | `body` |
| selection | Setting whether to clear the copy or cut selected | boolean | false |
| onSuccess | Operation success callback | function(event?: ClipboardJS.Event): void | - |
| onError | Operation error callback | function(event?: ClipboardJS.Event): void | - |

## Developing

```sh
git clone git@github.com:freeshineit/react-clipboardjs-copy.git

cd react-clipboardjs-copy

pnpm install

## development
pnpm run dev

## test
pnpm run test

## production
pnpm run build
```

## Reference material

[clipboard.js](https://clipboardjs.com/)

## License

MIT © [Shine Shao](https://github.com/freeshineit)

---
_Source: https://npm.io/package/react-clipboardjs-copy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
