@platform/react
Version:
React refs and helpers.
15 lines (14 loc) • 401 B
JavaScript
export const copyToClipboard = (text) => {
try {
const el = document.createElement('textarea');
el.value = text;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
catch (error) {
const err = `Failed to copy text to clipboard.\n\n${text}`;
console.error(err);
}
};