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

clipboard

> 前端框架
开源

React Native 适用于 iOS 和 Android 的剪贴板 API。

766 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

React Native 适用于 iOS 和 Android 的剪贴板 API。

@react-native-clipboard/clipboard

Build Status Version Supports macOS, iOS, Android, and Windows MIT License Lean Core Badge

React Native Clipboard API for macOS, iOS, Android, and Windows.

macOS iOS Android Windows

Getting started

Install the library using either Yarn:

bash
yarn add @react-native-clipboard/clipboard

or npm:

bash
npm install --save @react-native-clipboard/clipboard

Link

React Native v0.60+

For iOS, use cocoapods to link the package.

run the following command:

$ npx pod-install

For android, the package will be linked automatically on build.

For React Native version 0.59 or older

React Native

Migrating from the core react-native module

This module was created when the Clipboard API was split out from the core of React Native. To migrate to this module you need to follow the installation instructions above and then change you imports from:

javascript
import {Clipboard} from 'react-native';

to:

javascript
import Clipboard from '@react-native-clipboard/clipboard';

Example

…

Reference

Methods

Clipboard

getString()

javascript
static getString()

Get content of string type, this method returns a Promise, so you can use following code to get clipboard content

javascript
async _getContent() {
  var content = await Clipboard.getString();
}

getStrings()

javascript
static getStrings()

(iOS only) Get contents of string array type, this method returns a Promise, so you can use following code to get clipboard content

javascript
async _getContent() {
  var content = await Clipboard.getStrings();
}

setString()

javascript
static setString(content)

Set content of string type. You can use following code to set clipboard content

javascript
_setContent() {
  Clipboard.setString('hello world');
}

Parameters

Name Type Required Description
content string Yes The content to be stored in the clipboard

setStrings()

javascript
static setStrings(content)

(iOS only) Set content of string array type. You can use following code to set clipboard content

javascript
_setContent() {
  Clipboard.setStrings(['hello world', 'second string']);
}

Parameters

Name Type Required Description
content string[] Yes The content to be stored in the clipboard

hasString()

javascript
static hasString()

Returns whether the clipboard has content or is empty. Can check if there is a content in clipboard without triggering PasteBoard notification for iOS 14+

hasURL()

javascript
static hasURL()

(iOS only) Returns whether the clipboard has a URL content. Can check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+

hasNumber()

javascript
static hasNumber()

(iOS 14+ only) Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+

hasWebURL()

javascript
static hasWebURL()

(iOS 14+ only) Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+

useClipboard

useClipboard is a utility hooks for the Clipboard module. data contains the content stored in the clipboard.

javascript
import React, {useEffect} from 'react';
import {Text} from 'react-native';
import {useClipboard} from '@react-native-clipboard/clipboard';

export const HooksSample = () => {
  const [data, setString] = useClipboard();

  useEffect(() => {
    setString('hello world');
  }, []);

  return {data};
};

getImage()

javascript
static getImage()

Get content of image in base64 string type, this method returns a Promise, so you can use following code to get clipboard content (iOS and Android Only)

javascript
async _getContent() {
  var content = await Clipboard.getImage();
}

Mocking Clipboard

If you're using jest as a test runner, you will need to setup a mock for clipboard, as NativeModules will be undefined when testing with Jest.

Create a jest.setup.js in your project root,and set up the following to have Clipboard mocked:

javascript
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js';

jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);

Maintainers

  • M.Haris Baig
  • Jesse Katsumata

Contributing

Please see the contributing guide.

License

The library is released under the MIT licence. For more information see LICENSE.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

C++clipboardhacktoberfestreact-native

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

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架