(text: string, options?: CopyOptions)
| 16 | * Copy text to clipboard with error handling |
| 17 | */ |
| 18 | export const copyToClipboard = async (text: string, options?: CopyOptions): Promise<boolean> => { |
| 19 | try { |
| 20 | await navigator.clipboard.writeText(text) |
| 21 | options?.onSuccess?.() |
| 22 | return true |
| 23 | } catch (error) { |
| 24 | const err = error instanceof Error ? error : new Error("Failed to copy to clipboard") |
| 25 | options?.onError?.(err) |
| 26 | console.error("Failed to copy to clipboard:", err) |
| 27 | return false |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * React hook for managing clipboard copy state with feedback |
no test coverage detected