UNPKG

@sky-mavis/tanto-widget

Version:
19 lines 586 B
import {useState,useCallback,useEffect}from'react';function useClipboard(value, duration) { const [copied, setCopied] = useState(false); const handleCopy = useCallback(async () => { if (copied || !value) return; try { await navigator.clipboard.writeText(value.trim()); setCopied(true); } catch {} }, [value, copied]); useEffect(() => { if (!copied) return; const timer = setTimeout(() => setCopied(false), duration); return () => clearTimeout(timer); }, [copied, duration]); return { copied, handleCopy }; }export{useClipboard};