diff --git a/website/src/components/card/index.tsx b/website/src/components/card/index.tsx index 6d8cef9..c4e7285 100644 --- a/website/src/components/card/index.tsx +++ b/website/src/components/card/index.tsx @@ -1,4 +1,5 @@ import type { ReactNode } from "react" +import { useState } from "react" import { toast } from "sonner" import { Tooltip, @@ -16,14 +17,16 @@ interface CardProps { } const Card = (props: CardProps) => { - const [value, copy] = useCopyToClipboard() + const [copy] = useCopyToClipboard() + const [isCopied, setIsCopied] = useState(false) const copyToClipboard = async (txt: string) => { copy(txt) + setIsCopied(true) toast("Copied to clipboard!", { icon: , description: `${txt}`, - onAutoClose: () => copy(""), + onAutoClose: () => setIsCopied(false), }) } @@ -37,7 +40,7 @@ const Card = (props: CardProps) => { > {props.icon}

- {value ? "Copied!" : props.name} + {isCopied ? "Copied!" : props.name}

diff --git a/website/src/components/hero/index.tsx b/website/src/components/hero/index.tsx index 63f8c6e..0ec556f 100644 --- a/website/src/components/hero/index.tsx +++ b/website/src/components/hero/index.tsx @@ -12,7 +12,7 @@ import ExternalArrow from "../icons/externalArrow" import useCopyToClipboard from "@/hooks/useCopyToClipboard" const Hero = () => { - const [value, copy] = useCopyToClipboard() + const [copy, value] = useCopyToClipboard() const [popoverOpen, setPopoverOpen] = useState(false) const handleCopy = (command: iCommand) => { diff --git a/website/src/hooks/useCopyToClipboard.ts b/website/src/hooks/useCopyToClipboard.ts index c1cf9ff..f17cc7b 100644 --- a/website/src/hooks/useCopyToClipboard.ts +++ b/website/src/hooks/useCopyToClipboard.ts @@ -3,7 +3,7 @@ import { useState } from "react" type CopiedValue = string | null type CopyFn = (text: string) => Promise -function useCopyToClipboard(): [CopiedValue, CopyFn] { +function useCopyToClipboard(): [CopyFn, CopiedValue] { const [copiedText, setCopiedText] = useState(null) const copy: CopyFn = async (text) => { @@ -22,7 +22,7 @@ function useCopyToClipboard(): [CopiedValue, CopyFn] { } } - return [copiedText, copy] + return [copy, copiedText] } export default useCopyToClipboard