Skip to content

useCopy

Hook that manages copying text with status reset

browser
medium
test coverage
Last changed: 6 months ago

Installation

Library
CLI
Manual
typescript
import { useCopy } from '@siberiacancode/reactuse';

Usage

typescript
const { copied, value, copy } = useCopy();
## Demo

Api

Parameters

NameTypeDefaultNote
delay?number1000Delay in ms before resetting copied status

Returns

UseCopyReturn

Type declaration

typescript
export interface UseCopyReturn {
  /** Whether copy is in progress */
  copied: boolean;
  /** The copied value */
  value?: string;
  /** Function to copy text */
  copy: (value: string) => Promise<void>;
}

export interface UseCopyParams {
  /** Reset delay in milliseconds */
  resetDelay?: number;
}

Source

SourceDemo

Contributors

D
debabin
debabin

Released under the MIT License.