useClipboardItems

Almost same as useClipboard, but support multiple items via ClipboardItem.

Demo

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const clipboard = useClipboardItems(options)

Options

export type UseClipboardItemsOptions<Source> = { /** * Enabled reading for clipboard, need to request permission * * @defaultValue false */ read?: boolean /** * Copy source */ source?: Source /** * Milliseconds to reset state of `copied` ref * * @defaultValue 1500 */ copiedDuration?: number }

Returns

export type UseClipboardItemsReturns<Optional> = { /** * Check if the browser supports clipboard API */ isSupported: boolean /** * Clipboard items */ content: ClipboardItems /** * Check if the content is copied */ copied: boolean /** * Copy content to clipboard */ copy: Optional extends true ? (content?: ClipboardItems) => Promise<void> : (text: ClipboardItems) => Promise<void> /** * Clear clipboard */ clear(): void }