{"id":16836762,"url":"https://github.com/helderberto/use-clipboard-api","last_synced_at":"2025-07-13T00:35:42.738Z","repository":{"id":36953912,"uuid":"454022039","full_name":"helderberto/use-clipboard-api","owner":"helderberto","description":"📋 useClipboardApi() is a React Hook that consumes Web Clipboard API.","archived":false,"fork":false,"pushed_at":"2025-05-09T20:33:45.000Z","size":1877,"stargazers_count":22,"open_issues_count":10,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-02T15:17:07.154Z","etag":null,"topics":["clipboard","hook","react","react-hook","react-hooks","web-api","web-clipboard"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/helderberto.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}},"created_at":"2022-01-31T13:43:33.000Z","updated_at":"2024-12-11T21:52:28.000Z","dependencies_parsed_at":"2024-04-23T21:58:18.724Z","dependency_job_id":null,"html_url":"https://github.com/helderberto/use-clipboard-api","commit_stats":null,"previous_names":["helderburato/use-clipboard-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/helderberto/use-clipboard-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helderberto%2Fuse-clipboard-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helderberto%2Fuse-clipboard-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helderberto%2Fuse-clipboard-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helderberto%2Fuse-clipboard-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helderberto","download_url":"https://codeload.github.com/helderberto/use-clipboard-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helderberto%2Fuse-clipboard-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265075864,"owners_count":23707511,"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","hook","react","react-hook","react-hooks","web-api","web-clipboard"],"created_at":"2024-10-13T12:14:46.133Z","updated_at":"2025-07-13T00:35:42.706Z","avatar_url":"https://github.com/helderberto.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e📋 use-clipboard-api\u003c/h1\u003e\n\n  \u003cp\u003e\u003cstrong\u003euseClipboardApi() is a React Hook\u003c/strong\u003e that consumes Web Clipboard API.\u003c/p\u003e\n\n\u003c!-- prettier-ignore-start --\u003e\n[![build][build-badge]][build]\n[![version][version-badge]][package]\n[![MIT License][license-badge]][license]\n[![downloads][downloads-badge]][npmtrends]\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c/div\u003e\n\n---\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Motivation](#motivation)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Bugs and Sugestions](#bugs-and-sugestions)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Motivation\n\n- Easy way to use [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) into your React project;\n\n## Usage\n\nTo start using the `use-clipboard-api` in your project, first install in your project:\n\n`yarn add use-clipboard-api` or `npm install use-clipboard-api`\n\n\u003cdetails open\u003e\n\u003csummary\u003e\u003cstrong\u003eCopy to clipboard using a ref:\u003c/strong\u003e\u003c/summary\u003e\n\n```tsx\nimport React, { useRef } from 'react';\nimport useClipboardApi from 'use-clipboard-api';\n\nfunction ClipboardExampleWithRef() {\n  const inputRef = useRef\u003cHTMLInputElement | null\u003e(null);\n  const [copiedValue, copy, error] = useClipboardApi();\n\n  const handleCopy = async () =\u003e {\n    if (inputRef.current) {\n      const valueToCopy = inputRef.current.value;\n      const success = await copy(valueToCopy);\n\n      if (success) {\n        console.log('Text copied:', copiedValue);\n      } else {\n        console.error('Copy failed:', error);\n      }\n    }\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput ref={inputRef} type=\"text\" placeholder=\"Type something to copy\" /\u003e\n      \u003cbutton onClick={handleCopy}\u003eCopy to Clipboard\u003c/button\u003e\n      {copiedValue \u0026\u0026 \u003cp\u003eCopied: {copiedValue}\u003c/p\u003e}\n      {error \u0026\u0026 \u003cp style={{ color: 'red' }}\u003eError: {error}\u003c/p\u003e}\n    \u003c/div\u003e\n  );\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCopy to clipboard without using a ref:\u003c/strong\u003e\u003c/summary\u003e\n\n```tsx\nimport React, { useState } from 'react';\nimport useClipboardApi from 'use-clipboard-api';\n\nfunction ClipboardExampleWithoutRef() {\n  const [inputValue, setInputValue] = useState('');\n  const [copiedValue, copy, error] = useClipboardApi();\n\n  const handleCopy = async () =\u003e {\n    const success = await copy(inputValue);\n\n    if (success) {\n      console.log('Text copied:', copiedValue);\n    } else {\n      console.error('Copy failed:', error);\n    }\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput\n        type=\"text\"\n        value={inputValue}\n        onChange={(e) =\u003e setInputValue(e.target.value)}\n        placeholder=\"Type something to copy\"\n      /\u003e\n      \u003cbutton onClick={handleCopy}\u003eCopy to Clipboard\u003c/button\u003e\n      {copiedValue \u0026\u0026 \u003cp\u003eCopied: {copiedValue}\u003c/p\u003e}\n      {error \u0026\u0026 \u003cp style={{ color: 'red' }}\u003eError: {error}\u003c/p\u003e}\n    \u003c/div\u003e\n  );\n}\n```\n\n\u003c/details\u003e\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Bugs and Sugestions\n\nReport bugs or do suggestions using the [issues](https://github.com/helderberto/use-clipboard-api/issues).\n\n## License\n\n[MIT License](LICENSE) © [helderburato](https://helderberto.com)\n\n\u003c!-- prettier-ignore-start --\u003e\n[version-badge]: https://img.shields.io/npm/v/use-clipboard-api.svg?style=flat-square\n[package]: https://www.npmjs.com/package/use-clipboard-api\n[downloads-badge]: https://img.shields.io/npm/dm/use-clipboard-api.svg?style=flat-square\n[npmtrends]: http://www.npmtrends.com/use-clipboard-api\n[license-badge]: https://img.shields.io/npm/l/use-clipboard-api.svg?style=flat-square\n[license]: https://github.com/helderberto/use-clipboard-api/blob/master/LICENSE\n[build]: https://github.com/helderberto/use-clipboard-api/actions\n[build-badge]: https://github.com/helderberto/use-clipboard-api/actions/workflows/ci.yml/badge.svg\n\u003c!-- prettier-ignore-end --\u003e\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelderberto%2Fuse-clipboard-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelderberto%2Fuse-clipboard-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelderberto%2Fuse-clipboard-api/lists"}