@nextui-org/use-clipboard
Advanced tools
Comparing version 2.0.6 to 2.0.7
@@ -31,24 +31,30 @@ "use strict"; | ||
const [copyTimeout, setCopyTimeout] = (0, import_react.useState)(null); | ||
const onClearTimeout = () => { | ||
const onClearTimeout = (0, import_react.useCallback)(() => { | ||
if (copyTimeout) { | ||
clearTimeout(copyTimeout); | ||
} | ||
}; | ||
const handleCopyResult = (value) => { | ||
onClearTimeout(); | ||
setCopyTimeout(setTimeout(() => setCopied(false), timeout)); | ||
setCopied(value); | ||
}; | ||
const copy = (valueToCopy) => { | ||
if ("clipboard" in navigator) { | ||
navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err)); | ||
} else { | ||
setError(new Error("useClipboard: navigator.clipboard is not supported")); | ||
} | ||
}; | ||
const reset = () => { | ||
}, [copyTimeout]); | ||
const handleCopyResult = (0, import_react.useCallback)( | ||
(value) => { | ||
onClearTimeout(); | ||
setCopyTimeout(setTimeout(() => setCopied(false), timeout)); | ||
setCopied(value); | ||
}, | ||
[onClearTimeout, timeout] | ||
); | ||
const copy = (0, import_react.useCallback)( | ||
(valueToCopy) => { | ||
if ("clipboard" in navigator) { | ||
navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err)); | ||
} else { | ||
setError(new Error("useClipboard: navigator.clipboard is not supported")); | ||
} | ||
}, | ||
[handleCopyResult] | ||
); | ||
const reset = (0, import_react.useCallback)(() => { | ||
setCopied(false); | ||
setError(null); | ||
onClearTimeout(); | ||
}; | ||
}, [onClearTimeout]); | ||
return { copy, reset, error, copied }; | ||
@@ -55,0 +61,0 @@ } |
{ | ||
"name": "@nextui-org/use-clipboard", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Wrapper around navigator.clipboard with feedback timeout", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6932
122