Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update useCopyToClipboard to handle multiple formats #329

Open
kdawgwilk opened this issue Feb 24, 2025 · 0 comments
Open

Update useCopyToClipboard to handle multiple formats #329

kdawgwilk opened this issue Feb 24, 2025 · 0 comments

Comments

@kdawgwilk
Copy link

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]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant