react-use-clipboard
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

📋 react-use-clipboard

NPM version Test build status Bundle size Bundle size

A React Hook that provides copy to clipboard functionality.

Install

You can install react-use-clipboard with NPM or Yarn.

npm install react-use-clipboard
yarn add react-use-clipboard

Usage

Here's how to use react-use-clipboard:

import useClipboard from "react-use-clipboard";

function App() {
  const [isCopied, setCopied] = useClipboard("Text to copy");

  return (
    <button onClick={setCopied}>
      Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}
    </button>
  );
}

You can reset the isCopied value after a certain amount of time with the successDuration option.

import useClipboard from "react-use-clipboard";

function App() {
  const [isCopied, setCopied] = useClipboard("Text to copy", {
    // `isCopied` will go back to `false` after 1000ms.
    successDuration: 1000,
  });

  return (
    <button onClick={setCopied}>
      Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}
    </button>
  );
}

This package only works in versions of React that support Hooks.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.9
    40,317
    • latest

Version History

Package Sidebar

Install

npm i react-use-clipboard

Weekly Downloads

59,602

Version

1.0.9

License

MIT

Unpacked Size

13.2 kB

Total Files

13

Last publish

Collaborators

  • danoc