Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
"use client";
import { useState, useCallback, useRef } from "react";
import { copyToClipboard } from "@/shared/utils/clipboard";
/**
* Hook for copy to clipboard with feedback.
* Uses shared copyToClipboard utility that works on both HTTP and HTTPS.
* @param {number} resetDelay - Time in ms before resetting copied state (default: 2000)
* @returns {{ copied: string|null, copy: (text: string, id?: string) => Promise<boolean> }}
*/
export function useCopyToClipboard(resetDelay = 2000) {
const [copied, setCopied] = useState<string | null>(null);
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const copy = useCallback(
async (text: string, id = "default"): Promise<boolean> => {
const success = await copyToClipboard(text);
if (success) {
setCopied(id);
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
timeoutRef.current = setTimeout(() => {
setCopied(null);
}, resetDelay);
}
return success;
},
[resetDelay]
);
return { copied, copy };
}