Created
June 1, 2025 12:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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