fix: 修复 React Hook useEffect 依赖项警告

修复了三个文件中的 ESLint 警告:
- src/components/clients/LiveConfigModal.tsx
- src/components/switch/LiveConfigModal.tsx
- src/hooks/useMcpServers.ts

使用 useCallback 包装函数,确保依赖项正确声明,避免潜在的无限循环和性能问题。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
coso
2025-12-14 18:33:50 +08:00
co-authored by Claude Sonnet 4.5
parent 42d140dfd5
commit a9610b857c
3 changed files with 11 additions and 11 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useCallback } from "react";
import { X, RefreshCw, FileText } from "lucide-react";
import { switchApi, AppType } from "@/lib/api/switch";
@@ -19,7 +19,7 @@ export function LiveConfigModal({ appType, onClose }: LiveConfigModalProps) {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const loadConfig = async () => {
const loadConfig = useCallback(async () => {
setLoading(true);
setError(null);
try {
@@ -30,11 +30,11 @@ export function LiveConfigModal({ appType, onClose }: LiveConfigModalProps) {
} finally {
setLoading(false);
}
};
}, [appType]);
useEffect(() => {
loadConfig();
}, [appType]);
}, [loadConfig]);
return (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
+4 -4
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useCallback } from "react";
import { X, RefreshCw, FileText } from "lucide-react";
import { switchApi, AppType } from "@/lib/api/switch";
@@ -19,7 +19,7 @@ export function LiveConfigModal({ appType, onClose }: LiveConfigModalProps) {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const loadConfig = async () => {
const loadConfig = useCallback(async () => {
setLoading(true);
setError(null);
try {
@@ -30,11 +30,11 @@ export function LiveConfigModal({ appType, onClose }: LiveConfigModalProps) {
} finally {
setLoading(false);
}
};
}, [appType]);
useEffect(() => {
loadConfig();
}, [appType]);
}, [loadConfig]);
return (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
+3 -3
View File
@@ -34,7 +34,7 @@ export function useMcpServers() {
};
// 从所有应用导入 MCP 配置
const importFromAllApps = async (): Promise<number> => {
const importFromAllApps = useCallback(async (): Promise<number> => {
setImporting(true);
try {
let total = 0;
@@ -47,7 +47,7 @@ export function useMcpServers() {
} finally {
setImporting(false);
}
};
}, [fetchServers]);
// 同步所有配置到实际配置文件
const syncAllToLive = async () => {
@@ -67,7 +67,7 @@ export function useMcpServers() {
}
};
init();
}, [fetchServers]);
}, [fetchServers, importFromAllApps]);
const addServer = async (server: Omit<McpServer, "id" | "created_at">) => {
const newServer: McpServer = {