useCopyToClipboard
Copy text to a user's clipboard.
API
function useCopyToClipboard(): CopyToClipboardReturns;
Usage
import { useCopyToClipboard } from '@feedzai/js-utilities/hooks';
function App(props) {
const [text, setText] = useState('');
const { value, error, copyToClipboard } = useCopyToClipboard();
return (
<div>
<input value={text} onChange={e => setText(e.target.value)} />
<button type="button" onClick={() => copyToClipboard(text)}>copy text</button>
{error
? <p>Unable to copy value: {error.message}</p>
: value && <p>Copied {value}</p>
}
</div>
):
}