mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 16:18:07 +01:00
1747f91bf1
Fixes #8790
29 lines
648 B
JavaScript
29 lines
648 B
JavaScript
import { useState, useCallback } from 'react'
|
|
import copyToClipboard from 'copy-to-clipboard'
|
|
import { useTimeout } from './useTimeout'
|
|
|
|
/**
|
|
* useCopyToClipboard
|
|
*
|
|
* @param {number} [delay=3000] - delay in ms
|
|
*
|
|
* @return {[boolean, Function]}
|
|
*/
|
|
const DEFAULT_DELAY = 3000
|
|
|
|
export function useCopyToClipboard (delay = DEFAULT_DELAY) {
|
|
const [copied, setCopied] = useState(false)
|
|
const startTimeout = useTimeout(() => setCopied(false), delay, false)
|
|
|
|
const handleCopy = useCallback(
|
|
(text) => {
|
|
setCopied(true)
|
|
startTimeout()
|
|
copyToClipboard(text)
|
|
},
|
|
[startTimeout],
|
|
)
|
|
|
|
return [copied, handleCopy]
|
|
}
|