Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/danoc/react-use-clipboard

React hook that provides copy to clipboard functionality.
https://github.com/danoc/react-use-clipboard

clipboard component hooks react

Last synced: about 1 month ago
JSON representation

React hook that provides copy to clipboard functionality.

Awesome Lists containing this project

README

        

# 📋 react-use-clipboard

[![NPM version](https://badgen.net/npm/v/react-use-clipboard)](https://www.npmjs.com/package/react-use-clipboard) [![Test build status](https://github.com/danoc/react-use-clipboard/workflows/Test/badge.svg)](https://github.com/danoc/react-use-clipboard/actions?query=workflow%3ATest) [![Bundle size](https://badgen.net/bundlephobia/min/react-use-clipboard?label=size)](https://bundlephobia.com/result?p=react-use-clipboard) [![Bundle size](https://badgen.net/bundlephobia/minzip/react-use-clipboard?label=gzip%20size)](https://bundlephobia.com/result?p=react-use-clipboard)

> A React Hook that provides copy to clipboard functionality.

## Install

You can install `react-use-clipboard` with npm, Yarn, or pnpm.

```bash
npm install react-use-clipboard
yarn add react-use-clipboard
pnpm install react-use-clipboard
```

## Usage

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

```jsx
import useClipboard from "react-use-clipboard";

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

return (

Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}

);
}
```

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

```jsx
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 (

Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}

);
}
```

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