Skip to content

Instantly share code, notes, and snippets.

@RuanAragao
Created October 5, 2020 02:17
Show Gist options
  • Save RuanAragao/57a3905726127a25ceaa8d0c428082fe to your computer and use it in GitHub Desktop.
Save RuanAragao/57a3905726127a25ceaa8d0c428082fe to your computer and use it in GitHub Desktop.
Copy to clipboard function Typescript
const copyToClipboard = (str: string) => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment