Frontend Blocks typescript Beginner

Copy to Clipboard Button

React component that copies text to clipboard and shows a Copied! confirmation.

typescript
import { useState } from 'react';
export function CopyButton({ text }) {
  const [copied, setCopied] = useState(false);
  const copy = async () => {
    await navigator.clipboard.writeText(text);
    setCopied(true);
    setTimeout(() => setCopied(false), 2000);
  };
  return (
    <button onClick={copy} className='px-3 py-1 rounded-lg border text-sm'>
      {copied ? 'Copied!' : 'Copy'}
    </button>
  );
}

Prerequisites

  • React >= 17

Pro Tips

  • → Fallback with document.execCommand for older browsers.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
typescript
Level
Beginner
Read time
1 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.