Copy Text to Clipboard
This feature allows you to copy text to the clipboard. The example demonstrates a simple input field where the user can type text, and a button to copy that text to the clipboard. When the text is copied, a message is displayed.
import React, { useState } from 'react';
import { CopyToClipboard } from 'react-copy-to-clipboard';
const CopyExample = () => {
const [text, setText] = useState('Hello, World!');
const [copied, setCopied] = useState(false);
return (
<div>
<input value={text} onChange={(e) => setText(e.target.value)} />
<CopyToClipboard text={text} onCopy={() => setCopied(true)}>
<button>Copy to Clipboard</button>
</CopyToClipboard>
{copied ? <span style={{ color: 'red' }}>Copied.</span> : null}
</div>
);
};
export default CopyExample;