Skip to content

Commit 8589faa

Browse files
committed
refactor: Use useCopy() in JsonView
1 parent 59504ac commit 8589faa

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

client/src/components/JsonView.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Copy, CheckCheck } from "lucide-react";
55
import { Button } from "@/components/ui/button";
66
import { useToast } from "@/lib/hooks/useToast";
77
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
8+
import useCopy from "@/lib/hooks/useCopy";
89

910
interface JsonViewProps {
1011
data: unknown;
@@ -25,21 +26,7 @@ const JsonView = memo(
2526
isError = false,
2627
}: JsonViewProps) => {
2728
const { toast } = useToast();
28-
const [copied, setCopied] = useState(false);
29-
30-
useEffect(() => {
31-
let timeoutId: NodeJS.Timeout;
32-
if (copied) {
33-
timeoutId = setTimeout(() => {
34-
setCopied(false);
35-
}, 500);
36-
}
37-
return () => {
38-
if (timeoutId) {
39-
clearTimeout(timeoutId);
40-
}
41-
};
42-
}, [copied]);
29+
const { copied, setCopied } = useCopy();
4330

4431
const normalizedData = useMemo(() => {
4532
return typeof data === "string"

0 commit comments

Comments
 (0)