UseClipboard

use-clipboard hook provides interface to work with navigator.clipboard

Usage

Code Editor
Copy
import { useClipboard } from '@erudilabs/alma'

const { copy, copied } = useClipboard({ timeout: 500 })

Code Editor
Copy
<Button
  theme={copied ? 'success' : 'primary'}
  onClick={() => copy('Hello, world!')}
>
  {copied ? 'Copied!' : 'Copy'}
</Button>

Definition

Code Editor
Copy
function useClipboard(options: { timeout: number } = { timeout: 2000 }): {
  copy: (valueToCopy: any) => void;
  error: Error;
  copied: boolean;
};