@uxui/use-clipboard
v0.0.2
Published
React hook helps ease the work of copying to clipboard.
Downloads
3
Maintainers
Readme
use-clipboard
React hook helps ease the work of copying to clipboard.
Install
npm install --save @uxui/use-clipboard
Return
copy: (content: string) => void
: copy any thing passed to paramcontent
to clipboard.copied: boolean
: state whick will get truthy aftercopy()
gets called.turnOffCopied: () => void
: simply setcopied
tofalse
.
Usage
import React from "react";
import useClipboard from "@uxui/useClipboard";
export const App = () => {
const { copied, copy, turnOffCopied } = useClipboard();
const message = "Some text need to be copied";
return (
<div>
<div>{message}</div>
{copied ? (
<span>copied</span>
) : (
<button
onClick={() => {
copy(message);
setTimeout(() => {
turnOffCopied();
}, 1000);
}}
>
Copy to clipboard
</button>
)}
</div>
);
};
License
MIT © zlatanpham