Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

clipboard

> 前端框架
Open source

React Native Clipboard API for both iOS and Android.

766 stars0 likes3 views
WebsiteGitHub

About

React Native Clipboard API for both iOS and Android.

@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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++clipboardhacktoberfestreact-native

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

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