Skip to content

Commit

Permalink
Finish feature/156
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcastillop authored Jan 2, 2025
2 parents fb985f5 + cbd1066 commit 8d8ec4d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/examples/how-to-copy-api-key-clipboard/CopyApiKeys.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<ul>
{APIKeys.map((key) => (
<li key={key.id}>
<div>
<p>{key.name}</p>
<p>{key.value}</p>
</div>
<button onClick={() => handleCopy(key.value, key.name)}>
{copiedText === key.value ? 'Copied!' : 'Copy'}
</button>
</li>
))}
</ul>
);
};

0 comments on commit 8d8ec4d

Please sign in to comment.