Skip to content

useCopy

Hook that manages copying text with status reset

browser
medium
test coverage
Last changed: 8 months ago

TIP

This hook uses navigator.clipboard browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

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.