usehooks icon indicating copy to clipboard operation
usehooks copied to clipboard

Update useCopyToClipboard to handle multiple formats

Open kdawgwilk opened this issue 8 months ago • 0 comments

Example of how to do this outside this hook. Would be nice to use this hook and be able to pass multiple formats.

const plainText = "Hello, this is plain text!";
const htmlText = `<p style="color:blue;">Hello, this is <strong>HTML</strong> text!</p>`;
const markdownText = "**Hello**, this is Markdown text!";

// Create a ClipboardItem with multiple formats
const clipboardItem = new ClipboardItem({
  "text/plain": new Blob([plainText], { type: "text/plain" }),
  "text/html": new Blob([htmlText], { type: "text/html" }),
  "text/markdown": new Blob([markdownText], { type: "text/markdown" }),
});

// Write to clipboard
await navigator.clipboard.write([clipboardItem]);

kdawgwilk avatar Feb 24 '25 22:02 kdawgwilk