use-clipboard-copier
v1.0.4
Published
A react hook which helps you copy text to your clipboard.
Downloads
9
Maintainers
Readme
useClipBoardCopier 🪝
A React hook which helps you copy text to your clipboard 📋
Installation
npm install use-clipboard-copier
Usage
import React from "react";
import { useClipBoardCopier } from "use-clipboard-copier";
const hasCopiedTimer = 10000; // 10 seconds
const App: React.FC = () => {
const { isCopied, clipBoardRef, copyToClipBoard } =
useClipBoardCopier(hasCopiedTimer);
const handleCopyClick = () => {
copyToClipBoard();
};
return (
<div>
<input ref={clipBoardRef} placeholder="type something..." />
<button onClick={handleCopyClick}>Copy to Clipboard</button>
{isCopied ? <p>Copied</p> : <p>Copy</p>}
</div>
);
};
export default App;
Note: This hook works with all
HTML ELEMENTS
includingINPUT ELEMENT
as well.