use-clipboard
Wrapper around navigator.clipboard with feedback timeout
Import
Source
Docs
Package
Usage
use-clipboard hook provides interface to work with navigator.clipboard
:
import { Button } from '@mantine/core';import { useClipboard } from '@mantine/hooks';export function Demo() {const clipboard = useClipboard({ timeout: 500 });return (<Buttoncolor={clipboard.copied ? 'teal' : 'blue'}onClick={() => clipboard.copy('Hello, world!')}>{clipboard.copied ? 'Copied' : 'Copy'}</Button>);}
API
use-clipboard hook accepts one argument options
in which copied status timeout duration is defined (defaults to 2000).
Hook returns object with properties:
copy
– function to copy value to clipboardcopied
– value that indicates that copy handler was called less thanoptions.timeout
ms agoreset
– function to clear timeout and resetcopied
to falseerror
– containsError
object if something goes wrong
Definition
function useClipboard(options: { timeout: number } = { timeout: 2000 }): {copy: (valueToCopy: any) => void;reset: () => void;error: Error;copied: boolean;};
Built by Vitaly Rtishchev and these awesome people