百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-copy-to-clipboard

> 编程语言
开源

复制到剪贴板的 React 组件

2.4K stars0 点赞2 次浏览
访问官网GitHub

工具介绍

复制到剪贴板的 React 组件

react-copy-to-clipboard

Copy to clipboard React component

Based on 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'

Installation

Yarn

bash
yarn add react-copy-to-clipboard

NPM

bash
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

Codepen demo

https://codepen.io/nkbt/pen/eNPoQv

Usage

javascript
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 (
      

    );
  }
}

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 options.

See API docs 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.

javascript
<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 [email protected]: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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言