Use Copied
Writes a string to the clipboard and holds a copied flag for two seconds, so a control can confirm the copy.
sk_relay_7f21c0e4b98a3d55The flag clears itself two seconds after the write lands, so the button goes back to asking rather than staying answered.
Installation
npx shadcn@latest add @afterglow/use-copiedAPI Reference
Takes either the string to copy or a function returning it, which may be async. A function is re-read on every click, so a value that changes does not need the hook to be re-created.
copied clears itself two seconds later. A clipboard the browser denies, which is what happens when the document is not focused, leaves the flag alone instead of rejecting.
useCopied
Returns { copied, copy }. Wire copy to the control's onClick and read copied to swap its icon or label.