kitzo

React utilities library

useCopy

Copy text to the clipboard with status tracking and optional reset delay.

Usage

Copy.tsx
const { copy, status, isCopied, isCopying, isError } = useCopy(resetDelay);

Example

Status: standby

CopyExample.tsx
import { useCopy } from 'kitzo';
            
function CopyDemo() {
  const { copy, status } = useCopy(2000);

  return (
    <div>
      <input onChange={(e) => setText(e.target.value)} />
      <button onClick={() => copy(text)}>Copy</button>
      <p>Status: {status}</p>
    </div>
  );
}

API

ParameterTypeDescription
resetDelay
number

Time in milliseconds to reset the copy status to standby

Returns a copy function and status flags to track the copy process.

Behavior

  • Tracks copy status: standby, copying, copied, or error
  • Automatically resets to standby after resetDelay
  • Prevents multiple simultaneous copy operations
  • Provides convenient boolean flags: isCopying, isCopied, isError, isStandby