Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kashyapkaki/a438ed0fe7c957db4fad9ddf6946c88f to your computer and use it in GitHub Desktop.
Save kashyapkaki/a438ed0fe7c957db4fad9ddf6946c88f to your computer and use it in GitHub Desktop.
A simple utility that copies a string to the clipboard using the native navigator.clipboard API. Works great for "Copy" buttons in UI components, like sharing links or copying codes/passwords.
function copyToClipboard(text) {
navigator.clipboard.writeText(text)
.then(() => console.log('Copied!'))
.catch(err => console.error('Failed to copy:', err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment