We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
useCopy()
1 parent fd0b962 commit 1a60667Copy full SHA for 1a60667
client/src/lib/hooks/useCopy.ts
@@ -0,0 +1,29 @@
1
+"use client";
2
+
3
+import { useEffect, useState } from "react";
4
5
+type UseCopyProps = {
6
+ timeout?: number;
7
+};
8
9
+function useCopy({ timeout = 500 }: UseCopyProps = {}) {
10
+ const [copied, setCopied] = useState(false);
11
12
+ useEffect(() => {
13
+ let timeoutId: NodeJS.Timeout;
14
+ if (copied) {
15
+ timeoutId = setTimeout(() => {
16
+ setCopied(false);
17
+ }, timeout);
18
+ }
19
+ return () => {
20
+ if (timeoutId) {
21
+ clearTimeout(timeoutId);
22
23
+ };
24
+ }, [copied]);
25
26
+ return { copied, setCopied };
27
+}
28
29
+export default useCopy;
0 commit comments