BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/openstatus/use-copy-to-clipboard

Use Copy to Clipboard

openstatus/use-copy-to-clipboard
FreeHook

React hook for copying text to clipboard with toast notifications

Install it

npx shadcn@latest add https://openstatus.dev/r/use-copy-to-clipboard.json

Source

src/hooks/use-copy-to-clipboard.tsopenstatus.dev/r/use-copy-to-clipboard.json
1"use client";
2
3import { useCallback, useState } from "react";
4import { toast } from "sonner";
5
6export function useCopyToClipboard() {
7 const [text, setText] = useState<string | null>(null);
8
9 const copy = useCallback(
10 async (
11 text: string,
12 {
13 timeout = 3000,
14 withToast = false,
15 successMessage = "Copied to clipboard",
16 }: {
17 timeout?: number;
18 withToast?: boolean | string;
19 successMessage?: string;
20 },
21 ) => {
22 if (!navigator?.clipboard) {
23 console.warn("Clipboard not supported");
24 return false;
25 }
26
27 try {
28 await navigator.clipboard.writeText(text);
29 setText(text);
30
31 if (timeout) {
32 setTimeout(() => {
33 setText(null);
34 }, timeout);
35 }
36
37 if (withToast) {
38 if (typeof withToast === "string") {
39 toast.success(withToast);
40 } else {
41 toast.success(successMessage);
42 }
43 }
44
45 return true;
46 } catch (error) {
47 console.warn("Copy failed", error);
48 setText(null);
49 return false;
50 }
51 },
52 [],
53 );
54
55 return { text, copy, isCopied: text !== null };
56}

What it pulls in

Other registry items

  • sonner

Files it writes

  • src/hooks/use-copy-to-clipboard.ts

Facts

Registry
openstatus
Type
registry:hook
Access
Free
Files written
1
Licence
AGPL-3.0
First indexed
2026-08-01
Last confirmed
yesterday

Go to the source

openstatus.dev openstatusHQ/openstatus on GitHub Raw registry item This item as JSON

More from openstatus

All 26 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Use Media Queryuse-media-queryopenstatusHooksFreeno deps
BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex