react-reuse-hooks
Version:
A collection of 30+ production-ready reusable React hooks for web apps, covering state, effects, media, forms, and utilities.
18 lines (14 loc) • 400 B
JavaScript
import { useState } from "react";
export function useClipboard() {
const [copied, setCopied] = useState(false);
const copy = async (text) => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch (err) {
console.error("Failed to copy!", err);
}
};
return [copied, copy];
}