BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn-hooks/use-clipboard

use-clipboard

shadcn-hooks/use-clipboard
FreeHook

A hook to copy text to clipboard

Install it

npx shadcn@latest add https://shadcn-hooks.com/r/use-clipboard.json

Source

registry/hooks/use-clipboard.tsshadcn-hooks.com/r/use-clipboard.json
1import { useEffect, useMemo, useRef, useState } from 'react'
2import { useEventListener } from '@/registry/hooks/use-event-listener'
3import { useMemoizedFn } from '@/registry/hooks/use-memoized-fn'
4import { useUnmount } from '@/registry/hooks/use-unmount'
5import { isBrowser } from '@/registry/lib/is-browser'
6
7export interface UseClipboardOptions {
8 /**
9 * Enabled reading for clipboard
10 *
11 * @default false
12 */
13 read?: boolean
14
15 /**
16 * Copy source
17 */
18 source?: string
19
20 /**
21 * Milliseconds to reset state of `copied` ref
22 *
23 * @default 1500
24 */
25 copiedDuring?: number
26
27 /**
28 * Whether fallback to document.execCommand('copy') if clipboard is undefined.
29 *
30 * @default false
31 */
32 legacy?: boolean
33}
34
35export interface UseClipboardReturn {
36 isSupported: boolean
37 text: string
38 copied: boolean
39 copy: (text?: string) => Promise<void>
40}
41
42type PermissionState = 'granted' | 'denied' | 'prompt' | undefined
43
44function isAllowed(status: PermissionState): boolean {
45 return status === 'granted' || status === 'prompt'
46}
47
48function legacyCopy(value: string): void {
49 const ta = document.createElement('textarea')
50 ta.value = value
51 ta.style.position = 'absolute'
52 ta.style.opacity = '0'
53 ta.setAttribute('readonly', '')
54 document.body.appendChild(ta)
55 ta.select()
56 document.execCommand('copy')
57 ta.remove()
58}
59
60function legacyRead(): string {
61 return document?.getSelection?.()?.toString() ?? ''
62}
63
64/**
65 * Reactive Clipboard API.
66 *
67 * @param options - Configuration options
68 * @returns Clipboard state and methods
69 */
70export function useClipboard(
71 options: UseClipboardOptions = {},
72): UseClipboardReturn {
73 const { read = false, source, copiedDuring = 1500, legacy = false } = options
74
75 const [text, setText] = useState<string>('')
76 const [copied, setCopied] = useState<boolean>(false)
77 const [permissionRead, setPermissionRead] =
78 useState<PermissionState>(undefined)
79 const [permissionWrite, setPermissionWrite] =
80 useState<PermissionState>(undefined)
81
82 const timeoutRef = useRef<number | null>(null)
83
84 const isClipboardApiSupported = useMemo(() => {
85 if (!isBrowser) return false
86 return 'clipboard' in navigator
87 }, [])
88
89 const isSupported = useMemo(() => {
90 return isClipboardApiSupported || legacy
91 }, [isClipboardApiSupported, legacy])
92
93 // Check permissions
94 useEffect(() => {
95 if (!isBrowser || !isClipboardApiSupported) return
96
97 const checkPermissions = async () => {
98 try {
99// … truncated

What it pulls in

Other registry items

  • @shadcnhooks/use-unmount
  • @shadcnhooks/use-event-listener
  • @shadcnhooks/use-memoized-fn
  • @shadcnhooks/is-browser

Files it writes

  • registry/hooks/use-clipboard.ts

Facts

Registry
shadcn-hooks
Type
registry:hook
Access
Free
Files written
1
Licence
the repository states none
In the index
at or before 2026-08-11
Last confirmed
today

Go to the source

shadcn-hooks.com Debbl/shadcn-hooks on GitHub Raw registry item This item as JSON

More from shadcn-hooks

All 58 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
use-active-elementuse-active-elementshadcn-hooksHooksFreeno deps
use-batteryuse-batteryshadcn-hooksHooksFreeno deps
use-booleanuse-booleanshadcn-hooksHooksFreeno deps
use-click-any-whereuse-click-any-whereshadcn-hooksHooksFreeno deps
use-click-awayuse-click-awayshadcn-hooksHooksFreeno deps
use-controllable-valueuse-controllable-valueshadcn-hooksHooksFree1 dep
use-counteruse-countershadcn-hooksHooksFreeno deps
use-creationuse-creationshadcn-hooksHooksFree1 dep

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