@supunlakmal/hooks
Version:
A collection of reusable React hooks
25 lines (24 loc) • 836 B
TypeScript
/**
* Represents the result of the copy operation.
* - `null`: Initial state, no copy attempt made yet.
* - `true`: Copy successful.
* - `false`: Copy failed.
*/
type CopyStatus = null | boolean;
/**
* Represents the return value of the useCopyToClipboard hook.
* - `status`: The current status of the copy operation (null, true, or false).
* - `copy`: A function to trigger the copy operation.
*/
type UseCopyToClipboardReturn = [
status: CopyStatus,
copy: (text: string) => Promise<void>
];
/**
* Custom hook for copying text to the clipboard.
* Uses the modern Clipboard API (`navigator.clipboard.writeText`) with a fallback.
*
* @returns {UseCopyToClipboardReturn} A tuple containing the copy status and the copy function.
*/
export declare const useCopyToClipboard: () => UseCopyToClipboardReturn;
export {};