Skip to content

Commit 06cdc3f

Browse files
committed
write custom hook
1 parent e9ac06a commit 06cdc3f

File tree

3 files changed

+10143
-0
lines changed

3 files changed

+10143
-0
lines changed

Diff for: base-project-ts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@reduxjs/toolkit": "^1.9.6",
12+
"copy-to-clipboard": "^3.3.3",
1213
"formis-react": "^1.0.7",
1314
"react": "^18.2.0",
1415
"react-dom": "^18.2.0",

Diff for: base-project-ts/src/hooks/copyClipboard.hook.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useState } from "react";
2+
import copy from "copy-to-clipboard";
3+
4+
export const useCopyClipboard = (resetInterval = null) => {
5+
const [isCopied, setIsCopied] = useState(false);
6+
7+
const copyToClipboard = (text: string) => {
8+
if (typeof text === "string" || typeof text === "number") {
9+
copy(text.toString());
10+
setIsCopied(true);
11+
} else {
12+
setIsCopied(false);
13+
console.error(`Cannot copy typeof ${typeof text} to clipboard, must be a string or number.`);
14+
}
15+
};
16+
17+
return {
18+
copyToClipboard,
19+
isCopied,
20+
};
21+
};

0 commit comments

Comments
 (0)