useCopy

Free · MIT

Copy text and report what actually happened. "copied" only after the clipboard write resolves; a refused write reports "failed" (Candor's honest copy control: no success signal without a settled outcome).

Markdown

Preview

Install

With the Candor CLI

First time? Get started sets up the registry and theme. Or with shadcn directly: npx shadcn@latest add @candor/use-copy

Usage

TSX · The example above
"use client"

import { Check, Copy } from "lucide-react"
import { Button } from "@/components/ui/button"
import { useCopy } from "@/lib/use-copy"

export default function Example() {
  const { state, copy } = useCopy()
  return (
    <Button variant="outline" size="sm" onClick={() => copy("req_01JC8Z4M2V7Q")}>
      {state === "copied" ? <Check /> : <Copy />} {state === "copied" ? "Copied" : state === "failed" ? "Couldn’t copy" : "Copy the request id"}
    </Button>
  )
}

Functions

useCopy(resetAfter = 1600)

Copy text and report what actually happened. "copied" only after the clipboard write resolves; a refused write reports "failed" (Candor's honest copy control: no success signal without a settled outcome).

Types

CopyState
"idle" | "copying" | "copied" | "failed"