diff --git a/src/examples/how-to-copy-api-key-clipboard/CopyApiKeys.tsx b/src/examples/how-to-copy-api-key-clipboard/CopyApiKeys.tsx new file mode 100644 index 0000000..432ec16 --- /dev/null +++ b/src/examples/how-to-copy-api-key-clipboard/CopyApiKeys.tsx @@ -0,0 +1,36 @@ +import { useClipboard } from '../../hooks/ts/useClipboard'; + +const APIKeys = [ + { id: 1, name: 'API Key 1', value: '1234-5678-ABCD-EFGH' }, + { id: 2, name: 'API Key 2', value: 'IJKL-9876-MNOP-QRST' }, + { id: 3, name: 'API Key 3', value: 'UVWX-5432-YZAB-CDEF' } +]; + +export const CopyApiKeys = () => { + const { copiedText, copyToClipboard } = useClipboard(); + + const handleCopy = async (keyValue: string, keyName: string) => { + try { + await copyToClipboard(keyValue); + alert(`Copied: ${keyName}`); + } catch (e) { + alert('Failed to copy:'); + } + }; + + return ( +
{key.name}
+{key.value}
+