BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/zyeon/use-copy-to-clipboard

useCopyToClipboard

zyeon/use-copy-to-clipboard
FreeHook

A clipboard-copy hook with a timed copied state and a non-throwing error channel.

Install it

npx shadcn@latest add https://ui.zyeon.ai/r/use-copy-to-clipboard.json

Source

src/registry/hooks/use-copy-to-clipboard.tsxui.zyeon.ai/r/use-copy-to-clipboard.json
1"use client"
2
3import * as React from "react"
4
5export interface UseCopyToClipboardOptions {
6 /** How long `copied` stays true before falling back to false, in ms. Defaults to 2000. */
7 resetDelay?: number
8}
9
10export interface UseCopyToClipboardResult {
11 copied: boolean
12 copy: (text: string) => Promise<boolean>
13 error: Error | null
14}
15
16function toError(reason: unknown): Error {
17 if (reason instanceof Error) return reason
18 if (reason && typeof reason === "object" && "message" in reason) {
19 return new Error(String((reason as { message: unknown }).message))
20 }
21 return new Error("Clipboard write failed")
22}
23
24/**
25 * Clipboard copy plus an auto-resetting state machine. A successful `copy` sets
26 * `copied` to true and it falls back to false after `resetDelay`; calling `copy`
27 * again restarts the timer, and unmounting clears it. A failure (permission denied /
28 * insecure context / no API) only sets `error` and returns false — it never throws.
29 * The hook itself never touches `navigator` during render, only inside `copy`, so it
30 * is safe in a server-rendered component.
31 */
32export function useCopyToClipboard(
33 options: UseCopyToClipboardOptions = {},
34): UseCopyToClipboardResult {
35 const { resetDelay = 2000 } = options
36 const [copied, setCopied] = React.useState(false)
37 const [error, setError] = React.useState<Error | null>(null)
38 const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null)
39
40 const clearResetTimer = () => {
41 if (timeoutRef.current !== null) {
42 clearTimeout(timeoutRef.current)
43 timeoutRef.current = null
44 }
45 }
46
47 // Clean up on unmount, so a late timer can't setState on a gone component.
48 React.useEffect(() => clearResetTimer, [])
49
50 const copy = React.useCallback(
51 (text: string) => {
52 if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
53 setError(new Error("Clipboard API unavailable (insecure context or unsupported browser)"))
54 return Promise.resolve(false)
55 }
56
57 return navigator.clipboard.writeText(text).then(
58 () => {
59 setError(null)
60 setCopied(true)
61 clearResetTimer()
62 timeoutRef.current = setTimeout(() => {
63 setCopied(false)
64 timeoutRef.current = null
65 }, resetDelay)
66 return true
67 },
68 reason => {
69 setError(toError(reason))
70 return false
71 },
72 )
73 },
74 [resetDelay],
75 )
76
77 return { copied, copy, error }
78}
79
80// … truncated

Files it writes

  • src/registry/hooks/use-copy-to-clipboard.tsx

Facts

Registry
zyeon
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-13
Last confirmed
today

Go to the source

ui.zyeon.ai Zyeon-AI/zyeon-ui-components on GitHub Raw registry item This item as JSON

More from zyeon

All 893 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useAsyncuse-asynczyeonHooksFreeno deps
useBatteryuse-batteryzyeonHooksFreeno deps
useBroadcastChanneluse-broadcast-channelzyeonHooksFreeno deps
useClickOutsideuse-click-outsidezyeonHooksFreeno deps
useClipboardPasteuse-clipboard-pastezyeonHooksFreeno deps
useControllableStateuse-controllable-statezyeonHooksFreeno deps
useCookieuse-cookiezyeonHooksFreeno deps
useCountdownuse-countdownzyeonHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex