useCopyToClipboard
Custom hook that copies text to the clipboard using the [
Clipboard API](https://developer.Installation
npx sse-tool add use-copy-to-clipboard
npm install sse-hooks
Usage
import { useCopyToClipboard } from "./{hooks file}";
const [copiedText, copyToClipboard] = useCopyToClipboard();
const textToCopy = "Hello, world!";
// Attempt to copy text to the clipboard
copyToClipboard(textToCopy).then((success) => {
if (success) {
console.log(`Text "${textToCopy}" copied to clipboard successfully.`);
} else {
console.error("Failed to copy text to clipboard.");
}
});
import { useCopyToClipboard } from "sse-hooks";
const [copiedText, copyToClipboard] = useCopyToClipboard();
const textToCopy = "Hello, world!";
// Attempt to copy text to the clipboard
copyToClipboard(textToCopy).then((success) => {
if (success) {
console.log(`Text "${textToCopy}" copied to clipboard successfully.`);
} else {
console.error("Failed to copy text to clipboard.");
}
});
API
Return Value
Returns any.
An tuple containing the copied text and a function to copy text to the clipboard.