diff --git a/src/components/clients/LiveConfigModal.tsx b/src/components/clients/LiveConfigModal.tsx index 85067c3c6..9acac4dec 100644 --- a/src/components/clients/LiveConfigModal.tsx +++ b/src/components/clients/LiveConfigModal.tsx @@ -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(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 (
diff --git a/src/components/switch/LiveConfigModal.tsx b/src/components/switch/LiveConfigModal.tsx index 85067c3c6..9acac4dec 100644 --- a/src/components/switch/LiveConfigModal.tsx +++ b/src/components/switch/LiveConfigModal.tsx @@ -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(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 (
diff --git a/src/hooks/useMcpServers.ts b/src/hooks/useMcpServers.ts index 56e949835..a74c7623d 100644 --- a/src/hooks/useMcpServers.ts +++ b/src/hooks/useMcpServers.ts @@ -34,7 +34,7 @@ export function useMcpServers() { }; // 从所有应用导入 MCP 配置 - const importFromAllApps = async (): Promise => { + const importFromAllApps = useCallback(async (): Promise => { 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) => { const newServer: McpServer = {