fix(CompanyOverview): 修复 React Strict Mode 下骨架屏闪现问题
- 移除所有 hooks 中的 finally 块,避免请求取消时错误更新状态 - 添加 hasLoaded 状态追踪首次加载完成 - CanceledError 时直接返回,不更新任何状态 - 使用派生 isLoading 状态确保骨架屏正确显示 修复的 hooks: - useShareholderData.ts - useManagementData.ts - useAnnouncementsData.ts - useDisclosureData.ts - useBasicInfo.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -34,14 +34,16 @@ export const useManagementData = (options: UseManagementDataOptions): UseManagem
|
||||
const { stockCode, enabled = true } = options;
|
||||
|
||||
const [management, setManagement] = useState<Management[]>([]);
|
||||
const [loading, setLoading] = useState(() => enabled && !!stockCode);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// 记录是否已完成首次加载,用于派生 loading 状态
|
||||
const [hasLoaded, setHasLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// 只有 enabled 且有 stockCode 时才请求
|
||||
if (!enabled || !stockCode) return;
|
||||
if (!enabled || !stockCode) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
|
||||
@@ -60,11 +62,15 @@ export const useManagementData = (options: UseManagementDataOptions): UseManagem
|
||||
} else {
|
||||
setError("加载管理团队数据失败");
|
||||
}
|
||||
setLoading(false);
|
||||
setHasLoaded(true);
|
||||
} catch (err: any) {
|
||||
if (err.name === "CanceledError") return;
|
||||
// 请求被取消时,不更新任何状态
|
||||
if (err.name === "CanceledError") {
|
||||
return;
|
||||
}
|
||||
logger.error("useManagementData", "loadData", err, { stockCode });
|
||||
setError("网络请求失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setHasLoaded(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user