Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { useCallback } from "react";
2import { toast } from "sonner";
3
4const useCopyToClipboard = (
5 text: string,
6 successMessage = "Copied to clipboard!",
7 errorMessage = "Failed to copy"
8) => {
9 return useCallback(async () => {
10 try {
11 if (!navigator?.clipboard?.writeText) {
12 throw new Error("Clipboard API not available");
13 }
14
15 await navigator.clipboard.writeText(text);
16 toast.success(successMessage);
17 } catch {
18 toast.error(errorMessage);
19 }
20 }, [text, successMessage, errorMessage]);
21};
22
23export default useCopyToClipboard;