refactor: Use useCopy() in JsonView
This commit is contained in:
parent
59504ac336
commit
8589faa4c4
1 changed files with 2 additions and 15 deletions
|
|
@ -5,6 +5,7 @@ import { Copy, CheckCheck } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useToast } from "@/lib/hooks/useToast";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
|
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
|
||||||
|
import useCopy from "@/lib/hooks/useCopy";
|
||||||
|
|
||||||
interface JsonViewProps {
|
interface JsonViewProps {
|
||||||
data: unknown;
|
data: unknown;
|
||||||
|
|
@ -25,21 +26,7 @@ const JsonView = memo(
|
||||||
isError = false,
|
isError = false,
|
||||||
}: JsonViewProps) => {
|
}: JsonViewProps) => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [copied, setCopied] = useState(false);
|
const { copied, setCopied } = useCopy();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let timeoutId: NodeJS.Timeout;
|
|
||||||
if (copied) {
|
|
||||||
timeoutId = setTimeout(() => {
|
|
||||||
setCopied(false);
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
if (timeoutId) {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [copied]);
|
|
||||||
|
|
||||||
const normalizedData = useMemo(() => {
|
const normalizedData = useMemo(() => {
|
||||||
return typeof data === "string"
|
return typeof data === "string"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue