1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/app/hooks/useCopyToClipboard.js
Erik Marks 76a2a9bb8b
@metamask/eslint config@5.0.0 (#10358)
* @metamask/eslint-config@5.0.0
* Update eslintrc and prettierrc
* yarn lint:fix
2021-02-04 10:15:23 -08:00

29 lines
655 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];
}