@utilityjs/use-copy-to-clipboard
v1.0.1
Published
A React hook for copying text to the clipboard.
Downloads
24
Maintainers
Readme
A React hook for copying text to the clipboard.
npm i @utilityjs/use-copy-to-clipboard | yarn add @utilityjs/use-copy-to-clipboard
Usage
const App: React.FC = () => {
const [isCopied, setIsCopied] = React.useState(false);
const copy = useCopyToClipboard();
return (
<div className="app">
<button
disabled={isCopied}
onClick={async () => void setIsCopied(await copy("Hello, World!"))}
>
{isCopied ? "Copied!" : "Copy"}
</button>
</div>
);
};
API
useCopyToClipboard()
declare const useCopyToClipboard: () => (text: string) => Promise<boolean>;