fix(react): Add cancelAnimationFrame cleanup in useEffect

- Add cleanup function to cancel animation frame on unmount
- Prevents potential memory leaks and setState on unmounted component
- Closes #1093
This commit is contained in:
ClawdBot 2026-04-04 02:25:56 +03:00
parent c2bd2bc935
commit 805eacb9fc
3 changed files with 18 additions and 5 deletions

View file

@ -15,6 +15,14 @@ export function useApiKey(): UseApiKeyReturn {
const [copied, setCopied] = useState(false);
const [isLoading, setIsLoading] = useState(true);
// Clear copied state after 2 seconds
useEffect(() => {
if (copied) {
const timer = setTimeout(() => setCopied(false), 2000);
return () => clearTimeout(timer);
}
}, [copied]);
useEffect(() => {
// Load API key from localStorage
const loadApiKey = () => {
@ -41,9 +49,6 @@ export function useApiKey(): UseApiKeyReturn {
if (success) {
setCopied(true);
toast.success("API key copied to clipboard");
setTimeout(() => {
setCopied(false);
}, 2000);
} else {
toast.error("Failed to copy API key");
}