useCopy
Copies text and resets status after a delay.
Usage
import { useCopy } from "@siberiacancode/reactuse";
const copyState = useCopy();Example
const linkCopy = useCopy(1500);
return (
<button onClick={() => linkCopy.copy("https://reactuse.org")}>
{linkCopy.copied ? "Copied!" : "Copy link"}
</button>
);delay (reset timeout):
const copyState = useCopy(2000);Notes
- Hook uses the navigator.clipboard API.
Type Declarations
export interface UseCopyReturn {
copied: boolean;
value?: string;
copy: (value: string) => Promise<void>;
}
export declare const useCopy: (delay?: number) => UseCopyReturn;