react-use-clipboard-copy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/package.json +15 -0
- package/src/index.js +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# use-clipboard-copy
|
|
2
|
+
|
|
3
|
+
Simple React clipboard hook.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install use-clipboard-copy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
import { useClipboard } from "use-clipboard-copy";
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
const { copy, copied } = useClipboard();
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<button onClick={() => copy("Hello")}>
|
|
21
|
+
{copied ? "Copied!" : "Copy"}
|
|
22
|
+
</button>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-use-clipboard-copy",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple React hook for clipboard copy",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"hook",
|
|
9
|
+
"clipboard"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": ">=18"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
export function useClipboard(){
|
|
4
|
+
const [copied, setCopied] = useState(false);
|
|
5
|
+
|
|
6
|
+
const copy = async (text) =>{
|
|
7
|
+
try {
|
|
8
|
+
await navigator.clipboard.writeText(text);
|
|
9
|
+
setCopied(true);
|
|
10
|
+
return true;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
setCopied(false);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
copy,copied
|
|
19
|
+
}
|
|
20
|
+
}
|