useClipboard is a custom hook that handles copying content to clipboard.


The useClipboard hook takes the following arguments:

textstringtrueThe text or value that is to be copied.
optionsOrTimeoutnumber or objectfalseThe timeout as a number or an object containing 2 properties: timeout and format for the MIME type. The timeout is measured in milliseconds and has a default of 1500ms.

Return value#

The useClipboard hook returns an object with the following fields:

valuestringThe copied value.
onCopyfunctionCallback function to copy content.
hasCopiedbooleanfalseIf true, the content has been copied within the last timeout milliseconds. That is, it is set to true right after onCopy is called, and false after timeout has passed.


import { useClipboard } from '@chakra-ui/react'


function Example() {
const [value, setValue] = React.useState('Hello world')
const { hasCopied, onCopy } = useClipboard(value)
return (
<Flex mb={2}>
<Input value={value} isReadOnly placeholder='Welcome' />
<Button onClick={onCopy} ml={2}>
{hasCopied ? 'Copied' : 'Copy'}
<Editable placeholder='Paste here'>
<EditablePreview width='100%' />
<EditableInput />
Edit this page on GitHub

Proudly made inNigeria by Segun Adebayo

Deployed by Vercel