UNPKG

react-hookbox

Version:

react-hookbox is a comprehensive utility hook library for React developers, offering a diverse set of essential hooks to streamline and enhance your development process. Simplify complex tasks, handle common functionalities effortlessly, and boost your pr

18 lines (14 loc) 440 B
import { useState } from "react"; type ClipboardHookResult = [(data: string) => void, string]; export const useClipboard = (): ClipboardHookResult => { const [copied, setCopied] = useState(''); const copyToClipboard = (data: string) => { try { navigator.clipboard.writeText(data); setCopied(data); } catch (error) { console.error('Failed to copy: ', error); } }; return [copyToClipboard, copied]; }