import { useState } from "react"; import copy from "copy-to-clipboard"; interface Options { debug?: boolean; message?: string; format?: string; onCopy?: (clipboardData: object) => void; } type CopyToClipboardHookReturn = [ (text: string, options?: Options) => void, { value: string | null; success: boolean | null } ]; export default function useCopyToClipboard(): CopyToClipboardHookReturn { const [value, setValue] = useState(null); const [success, setSuccess] = useState(null); const copyToClipboard = (text: string, options?: Options) => { const result = copy(text, options); if (result) setValue(text); setSuccess(result); }; return [copyToClipboard, { value, success }]; }