# react-copy-to-clipboard

> Copy-to-clipboard React component

Latest version **5.1.1** (published 2026-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-copy-to-clipboard
pnpm add react-copy-to-clipboard
yarn add react-copy-to-clipboard
bun add react-copy-to-clipboard
```

## Health

**Score 53/100 (C)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.1.1 |
| Published | 2026-03-07 |
| First published | 2015-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/react-copy-to-clipboard) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 37 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2368 |
| Author | Nik Butenko |
| Maintainers | nkbt |
| Keywords | component, react-component, react, copy to clipboard, clipboard |

## Links

- npm: https://www.npmjs.com/package/react-copy-to-clipboard
- Repository: https://github.com/nkbt/react-copy-to-clipboard
- Issues: https://github.com/nkbt/react-copy-to-clipboard/issues
- npm.io page: https://npm.io/package/react-copy-to-clipboard

## Dependencies (2)

- [prop-types](https://npm.io/package/prop-types.md) ^15.8.1
- [copy-to-clipboard](https://npm.io/package/copy-to-clipboard.md) ^3.3.3

## 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

- 5.1.1 (latest) — 2026-03-07
- 5.1.0 — 2022-04-13
- 5.0.4 — 2021-08-17
- 5.0.3 — 2021-01-12
- 5.0.2 — 2019-11-08
- 5.0.1 — 2017-09-30
- 5.0.0 — 2017-04-26
- 4.3.1 — 2017-04-20
- 4.3.0 — 2017-04-12
- 4.2.3 — 2016-08-16
- 4.2.2 — 2016-07-27
- 4.2.1 — 2016-07-10
- 4.2.0 — 2016-07-05
- 4.1.1 — 2016-07-05
- 4.1.0 — 2016-04-12
- … 15 more at https://npm.io/package/react-copy-to-clipboard/versions

## README

# react-copy-to-clipboard [![npm](https://img.shields.io/npm/v/react-copy-to-clipboard.svg?style=flat-square)](https://www.npmjs.com/package/react-copy-to-clipboard)

[![CircleCI](https://img.shields.io/circleci/project/nkbt/react-copy-to-clipboard.svg?style=flat-square)](https://circleci.com/gh/nkbt/react-copy-to-clipboard)

Copy to clipboard React component

Based on [copy-to-clipboard](https://npm.im/copy-to-clipboard)

> Would try to use execCommand with fallback to IE specific clipboardData interface and finally, fallback to simple prompt with proper text content & 'Copy to clipboard: Ctrl+C, Enter'


![Copy to clipboard](example/copy-to-clipboard.gif)


## Installation

### Yarn

```sh
yarn add react-copy-to-clipboard
```

### NPM

```sh
npm install --save react-copy-to-clipboard
```

Don't forget to manually install peer dependencies (`react`) if you use npm@3.

## Simple web demo

[https://nkbt.github.io/react-copy-to-clipboard](https://nkbt.github.io/react-copy-to-clipboard)

## Codepen demo

[https://codepen.io/nkbt/pen/eNPoQv](https://codepen.io/nkbt/pen/eNPoQv?editors=0010)

## Usage
```js
import React from 'react';
import ReactDOM from 'react-dom';
import {CopyToClipboard} from 'react-copy-to-clipboard';

class App extends React.Component {
  state = {
    value: '',
    copied: false,
  };

  render() {
    return (
      <div>
        <input value={this.state.value}
          onChange={({target: {value}}) => this.setState({value, copied: false})} />

        <CopyToClipboard text={this.state.value}
          onCopy={() => this.setState({copied: true})}>
          <span>Copy to clipboard with span</span>
        </CopyToClipboard>

        <CopyToClipboard text={this.state.value}
          onCopy={() => this.setState({copied: true})}>
          <button>Copy to clipboard with button</button>
        </CopyToClipboard>

        {this.state.copied ? <span style={{color: 'red'}}>Copied.</span> : null}
      </div>
    );
  }
}

const appRoot = document.createElement('div');
document.body.appendChild(appRoot);
ReactDOM.render(<App />, appRoot);
```

## Options


#### `text`: PropTypes.string.isRequired

Text to be copied to clipboard


#### `onCopy`: PropTypes.func

Optional callback, will be called when text is copied

```
onCopy(text, result)
```
`result (bool)`: Returns `true` if copied successfully, else `false`.


#### `options`: PropTypes.shape({debug: bool, message: string, format: string})

Optional [copy-to-clipboard](https://npm.im/copy-to-clipboard) options.

See [API docs](https://npm.im/copy-to-clipboard#api) for details

#### `children`: PropTypes.element.isRequired

CopyToClipboard is a simple wrapping component, it does not render any tags, so it requires the only child element to be present, which will be used to capture clicks.

```js
<CopyToClipboard text="Hello!">
  <button>Copy to clipboard</button>
</CopyToClipboard>
```

## Development and testing

Currently is being developed and tested with the latest stable `Node` on `OSX`.

To run example covering all `CopyToClipboard` features, use `yarn start`, which will compile `example/Example.js`

```bash
git clone git@github.com:nkbt/react-copy-to-clipboard.git
cd react-copy-to-clipboard
yarn install
yarn start

# then
open http://localhost:8080
```

## Tests

```bash
# to run Biome check
yarn lint

# to run tests
yarn test
```

## License

MIT

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