{"id":15024966,"url":"https://github.com/react-native-clipboard/clipboard","last_synced_at":"2025-05-13T22:06:15.612Z","repository":{"id":37880209,"uuid":"169557152","full_name":"react-native-clipboard/clipboard","owner":"react-native-clipboard","description":"React Native Clipboard API for both iOS and Android.","archived":false,"fork":false,"pushed_at":"2025-03-03T11:25:48.000Z","size":2858,"stargazers_count":722,"open_issues_count":72,"forks_count":147,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-25T08:43:31.625Z","etag":null,"topics":["clipboard","hacktoberfest","react-native"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/react-native-clipboard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-07T10:53:29.000Z","updated_at":"2025-04-22T10:14:58.000Z","dependencies_parsed_at":"2023-12-21T13:58:28.731Z","dependency_job_id":"1b8088bb-2756-45cf-b068-44e1e6fc7210","html_url":"https://github.com/react-native-clipboard/clipboard","commit_stats":{"total_commits":142,"total_committers":31,"mean_commits":4.580645161290323,"dds":0.5633802816901409,"last_synced_commit":"c95742cdfaa86a927f98e06da1cdebe3e2887727"},"previous_names":["react-native-community/clipboard"],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-clipboard%2Fclipboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-clipboard%2Fclipboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-clipboard%2Fclipboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-clipboard%2Fclipboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-native-clipboard","download_url":"https://codeload.github.com/react-native-clipboard/clipboard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251516953,"owners_count":21601912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clipboard","hacktoberfest","react-native"],"created_at":"2024-09-24T20:01:17.459Z","updated_at":"2025-04-29T14:21:04.114Z","avatar_url":"https://github.com/react-native-clipboard.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @react-native-clipboard/clipboard\n\n[![Build Status][build-badge]][build]\n[![Version][version-badge]][package]\n![Supports macOS, iOS, Android, and Windows][support-badge]\n[![MIT License][license-badge]][license]\n[![Lean Core Badge][lean-core-badge]][lean-core-issue]\n\nReact Native Clipboard API for macOS, iOS, Android, and Windows.\n\n| macOS                                                                                                                        | iOS                                                                                                                           | Android                                                                                                                       | Windows                                                                                                                        |\n| ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |\n| \u003cimg src =\"https://user-images.githubusercontent.com/717674/90572309-8a381100-e168-11ea-92cb-ecad8e333d8f.png\" width=\"320\"/\u003e | \u003cimg src =\"https://user-images.githubusercontent.com/6936373/73284520-0ce29880-4238-11ea-9d0e-2061b2d6f17a.png\" width=\"320\"/\u003e | \u003cimg src =\"https://user-images.githubusercontent.com/6936373/73284517-0ce29880-4238-11ea-96c7-5a6337c43da5.png\" width=\"320\"/\u003e | \u003cimg src=\"https://user-images.githubusercontent.com/22989529/92150676-9bbe2180-edd4-11ea-8ef7-513451a00594.png\" width=\"320\" /\u003e |\n\n## Getting started\n\nInstall the library using either Yarn:\n\n```\nyarn add @react-native-clipboard/clipboard\n```\n\nor npm:\n\n```\nnpm install --save @react-native-clipboard/clipboard\n```\n\n## Link\n\n### React Native v0.60+\n\nFor iOS, use `cocoapods` to link the package.\n\nrun the following command:\n\n```\n$ npx pod-install\n```\n\nFor android, the package will be linked automatically on build.\n\n\u003cdetails\u003e\n  \u003csummary\u003eFor React Native version 0.59 or older\u003c/summary\u003e\n\n### React Native \u003c= 0.59\n\nrun the following command to link the package:\n\n```\n$ react-native link @react-native-clipboard/clipboard\n```\n\nFor iOS, make sure you install the pod file.\n\n```\ncd ios \u0026\u0026 pod install \u0026\u0026 cd ..\n```\n\nor you could follow the instructions to [manually link the project](https://reactnative.dev/docs/linking-libraries-ios#manual-linking)\n\n## Upgrading to React Native 0.60+\n\nNew React Native comes with `autolinking` feature, which automatically links Native Modules in your project. In order to get it to work, make sure you unlink `Clipboard` first:\n\n```\n$ react-native unlink @react-native-clipboard/clipboard\n```\n\n\u003c/details\u003e\n\n## Migrating from the core `react-native` module\n\nThis 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:\n\n```javascript\nimport {Clipboard} from 'react-native';\n```\n\nto:\n\n```javascript\nimport Clipboard from '@react-native-clipboard/clipboard';\n```\n\n## Example\n\n```jsx\nimport React, {useState} from 'react';\nimport {\n  SafeAreaView,\n  View,\n  Text,\n  TouchableOpacity,\n  StyleSheet,\n} from 'react-native';\nimport Clipboard from '@react-native-clipboard/clipboard';\n\nconst App = () =\u003e {\n  const [copiedText, setCopiedText] = useState('');\n\n  const copyToClipboard = () =\u003e {\n    Clipboard.setString('hello world');\n  };\n\n  const fetchCopiedText = async () =\u003e {\n    const text = await Clipboard.getString();\n    setCopiedText(text);\n  };\n\n  return (\n    \u003cSafeAreaView style={{flex: 1}}\u003e\n      \u003cView style={styles.container}\u003e\n        \u003cTouchableOpacity onPress={copyToClipboard}\u003e\n          \u003cText\u003eClick here to copy to Clipboard\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity onPress={fetchCopiedText}\u003e\n          \u003cText\u003eView copied text\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n\n        \u003cText style={styles.copiedText}\u003e{copiedText}\u003c/Text\u003e\n      \u003c/View\u003e\n    \u003c/SafeAreaView\u003e\n  );\n};\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    justifyContent: 'center',\n    alignItems: 'center',\n  },\n  copiedText: {\n    marginTop: 10,\n    color: 'red',\n  },\n});\n\nexport default App;\n```\n\n# Reference\n\n## Methods\n\n### Clipboard\n\n#### `getString()`\n\n```jsx\nstatic getString()\n```\n\nGet content of string type, this method returns a `Promise`, so you can use following code to get clipboard content\n\n```jsx\nasync _getContent() {\n  var content = await Clipboard.getString();\n}\n```\n\n#### `getStrings()`\n\n```jsx\nstatic getStrings()\n```\n\n(iOS only)\nGet contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content\n\n```jsx\nasync _getContent() {\n  var content = await Clipboard.getStrings();\n}\n```\n\n#### `setString()`\n\n```jsx\nstatic setString(content)\n```\n\nSet content of string type. You can use following code to set clipboard content\n\n```jsx\n_setContent() {\n  Clipboard.setString('hello world');\n}\n```\n\n#### Parameters\n\n| Name    | Type   | Required | Description                               |\n| ------- | ------ | -------- | ----------------------------------------- |\n| content | string | Yes      | The content to be stored in the clipboard |\n\n#### `setStrings()`\n\n```jsx\nstatic setStrings(content)\n```\n\n(iOS only)\nSet content of string array type. You can use following code to set clipboard content\n\n```jsx\n_setContent() {\n  Clipboard.setStrings(['hello world', 'second string']);\n}\n```\n\n#### Parameters\n\n| Name    | Type     | Required | Description                               |\n| ------- | -------- | -------- | ----------------------------------------- |\n| content | string[] | Yes      | The content to be stored in the clipboard |\n\n#### `hasString()`\n\n```jsx\nstatic hasString()\n```\n\nReturns whether the clipboard has content or is empty.\nCan check if there is a content in clipboard without triggering PasteBoard notification for iOS 14+\n\n#### `hasURL()`\n\n```jsx\nstatic hasURL()\n```\n\n(iOS only)\nReturns whether the clipboard has a URL content.\nCan check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+\n\n#### `hasNumber()`\n\n```jsx\nstatic hasNumber()\n```\n\n(iOS 14+ only)\nReturns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content.\nCan check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+\n\n#### `hasWebURL()`\n\n```jsx\nstatic hasWebURL()\n```\n\n(iOS 14+ only)\nReturns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content.\nCan check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+\n\n### useClipboard\n\n`useClipboard` is a utility hooks for the `Clipboard` module. `data` contains the content stored in the clipboard.\n\n```jsx\nimport React, {useEffect} from 'react';\nimport {Text} from 'react-native';\nimport {useClipboard} from '@react-native-clipboard/clipboard';\n\nexport const HooksSample = () =\u003e {\n  const [data, setString] = useClipboard();\n\n  useEffect(() =\u003e {\n    setString('hello world');\n  }, []);\n\n  return \u003cText\u003e{data}\u003c/Text\u003e;\n};\n```\n\n### `getImage()`\n\n```jsx\nstatic getImage()\n```\n\nGet 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)\n\n```jsx\nasync _getContent() {\n  var content = await Clipboard.getImage();\n}\n```\n\n## Mocking Clipboard\n\nIf 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.\n\nCreate a `jest.setup.js` in your project root,and set up the following to have Clipboard mocked:\n\n```js\nimport mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js';\n\njest.mock('@react-native-clipboard/clipboard', () =\u003e mockClipboard);\n```\n\n## Maintainers\n\n- [M.Haris Baig](https://github.com/harisbaig100)\n- [Jesse Katsumata](https://github.com/Naturalclar)\n\n## Contributing\n\nPlease see the [`contributing guide`](/CONTRIBUTING.md).\n\n## License\n\nThe library is released under the MIT licence. For more information see [`LICENSE`](/LICENSE).\n\n[build-badge]: https://github.com/react-native-clipboard/clipboard/workflows/Build/badge.svg\n[build]: https://github.com/react-native-clipboard/clipboard/actions\n[version-badge]: https://img.shields.io/npm/v/@react-native-clipboard/clipboard.svg?style=flat-square\n[package]: https://www.npmjs.com/package/@react-native-clipboard/clipboard\n[support-badge]: https://img.shields.io/badge/platforms-android%20|%20ios%20|%20macos%20|%20windows-lightgrey.svg?style=flat-square\n[license-badge]: https://img.shields.io/npm/l/@react-native-clipboard/clipboard.svg?style=flat-square\n[license]: https://opensource.org/licenses/MIT\n[lean-core-badge]: https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg?style=flat-square\n[lean-core-issue]: https://github.com/facebook/react-native/issues/23313\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-clipboard%2Fclipboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-native-clipboard%2Fclipboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-clipboard%2Fclipboard/lists"}