snort/src/useCopy.ts
ennmichael 5ad4971fc0
Add prettier formatting (#214)
* chore: add prettier

* chore: format codebase
2023-02-07 20:04:50 +00:00

21 lines
462 B
TypeScript

import { useState } from "react";
export const useCopy = (timeout = 2000) => {
const [error, setError] = useState(false);
const [copied, setCopied] = useState(false);
const copy = async (text: string) => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setError(false);
} catch (error) {
setError(true);
}
setTimeout(() => setCopied(false), timeout);
};
return { error, copied, copy };
};