useCopy ​
Hook that manages copying text with status reset
browser
test coverage
Last changed: last month
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
Name | Type | Default | Note |
---|---|---|---|
delay? | number | 1000 | Delay 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 | null;
/** Function to copy text */
copy: (value: string) => Promise<void>;
}
export interface UseCopyParams {
/** Reset delay in milliseconds */
resetDelay?: number;
}
Source ​
Source • DemoContributors ​
D