feat: 修改更新依赖

This commit is contained in:
zdl
2025-11-04 20:19:01 +08:00
parent c7334191e5
commit 38d1b51af3
2 changed files with 10 additions and 6 deletions

View File

@@ -63,11 +63,11 @@ function StockDetailPanel({ visible, event, onClose }) {
refreshQuotes refreshQuotes
} = useEventStocks(event?.id, event?.start_time); } = useEventStocks(event?.id, event?.start_time);
// 自选股管理 // 自选股管理(只在 Drawer 可见时加载)
const { const {
watchlistSet, watchlistSet,
toggleWatchlist toggleWatchlist
} = useWatchlist(); } = useWatchlist(visible);
// 实时监控管理 // 实时监控管理
const { const {

View File

@@ -9,9 +9,10 @@ import { logger } from '../../../../../utils/logger';
* 自选股管理 Hook * 自选股管理 Hook
* 封装自选股的加载、添加、移除逻辑 * 封装自选股的加载、添加、移除逻辑
* *
* @param {boolean} shouldLoad - 是否立即加载自选股列表(默认 true
* @returns {Object} 自选股数据和操作方法 * @returns {Object} 自选股数据和操作方法
*/ */
export const useWatchlist = () => { export const useWatchlist = (shouldLoad = true) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
// 从 Redux 获取自选股列表 // 从 Redux 获取自选股列表
@@ -23,10 +24,13 @@ export const useWatchlist = () => {
return new Set(watchlistArray); return new Set(watchlistArray);
}, [watchlistArray]); }, [watchlistArray]);
// 初始化时加载自选股列表 // 初始化时加载自选股列表(只在 shouldLoad 为 true 时)
useEffect(() => { useEffect(() => {
dispatch(loadWatchlist()); if (shouldLoad) {
}, [dispatch]); logger.debug('useWatchlist', '条件加载自选股列表', { shouldLoad });
dispatch(loadWatchlist());
}
}, [dispatch, shouldLoad]);
/** /**
* 检查股票是否在自选股中 * 检查股票是否在自选股中