diff --git a/src/views/Community/components/StockDetailPanel/hooks/useEventStocks.js b/src/views/Community/components/StockDetailPanel/hooks/useEventStocks.js index 90f596ff..354a14ae 100644 --- a/src/views/Community/components/StockDetailPanel/hooks/useEventStocks.js +++ b/src/views/Community/components/StockDetailPanel/hooks/useEventStocks.js @@ -1,5 +1,5 @@ // src/views/Community/components/StockDetailPanel/hooks/useEventStocks.js -import { useSelector, useDispatch } from 'react-redux'; +import { useSelector, useDispatch, shallowEqual } from 'react-redux'; import { useEffect, useCallback, useMemo } from 'react'; import { fetchEventStocks, @@ -24,14 +24,16 @@ export const useEventStocks = (eventId, eventTime) => { // 从 Redux 获取数据 const stocks = useSelector(state => - eventId ? (state.stock.eventStocksCache[eventId] || []) : [] + eventId ? (state.stock.eventStocksCache[eventId] || []) : [], + shallowEqual // 防止不必要的引用变化 ); - const quotes = useSelector(state => state.stock.quotes); + const quotes = useSelector(state => state.stock.quotes, shallowEqual); const eventDetail = useSelector(state => eventId ? state.stock.eventDetailsCache[eventId] : null ); const historicalEvents = useSelector(state => - eventId ? (state.stock.historicalEventsCache[eventId] || []) : [] + eventId ? (state.stock.historicalEventsCache[eventId] || []) : [], + shallowEqual // 防止不必要的引用变化 ); const chainAnalysis = useSelector(state => eventId ? state.stock.chainAnalysisCache[eventId] : null @@ -41,7 +43,7 @@ export const useEventStocks = (eventId, eventTime) => { ); // 加载状态 - const loading = useSelector(state => state.stock.loading); + const loading = useSelector(state => state.stock.loading, shallowEqual); // 加载所有数据 const loadAllData = useCallback(() => { @@ -91,7 +93,7 @@ export const useEventStocks = (eventId, eventTime) => { if (eventId) { loadAllData(); } - }, [loadAllData]); + }, [eventId]); // 修复:只依赖 eventId,避免无限循环 // 自动加载行情数据 useEffect(() => { diff --git a/src/views/Community/components/StockDetailPanel/hooks/useStockMonitoring.js b/src/views/Community/components/StockDetailPanel/hooks/useStockMonitoring.js index 9f988c4f..884a0196 100644 --- a/src/views/Community/components/StockDetailPanel/hooks/useStockMonitoring.js +++ b/src/views/Community/components/StockDetailPanel/hooks/useStockMonitoring.js @@ -1,5 +1,5 @@ // src/views/Community/components/StockDetailPanel/hooks/useStockMonitoring.js -import { useSelector, useDispatch } from 'react-redux'; +import { useSelector, useDispatch, shallowEqual } from 'react-redux'; import { useState, useEffect, useRef, useCallback } from 'react'; import { fetchStockQuotes } from '../../../../../store/slices/stockSlice'; import { message } from 'antd'; @@ -20,7 +20,7 @@ export const useStockMonitoring = (stocks = [], eventTime = null, interval = 500 const monitoringIntervalRef = useRef(null); // 从 Redux 获取行情数据和加载状态 - const quotes = useSelector(state => state.stock.quotes); + const quotes = useSelector(state => state.stock.quotes, shallowEqual); const quotesLoading = useSelector(state => state.stock.loading.quotes); /** diff --git a/src/views/Community/components/StockDetailPanel/hooks/useWatchlist.js b/src/views/Community/components/StockDetailPanel/hooks/useWatchlist.js index c1b8f031..81e94848 100644 --- a/src/views/Community/components/StockDetailPanel/hooks/useWatchlist.js +++ b/src/views/Community/components/StockDetailPanel/hooks/useWatchlist.js @@ -1,5 +1,5 @@ // src/views/Community/components/StockDetailPanel/hooks/useWatchlist.js -import { useSelector, useDispatch } from 'react-redux'; +import { useSelector, useDispatch, shallowEqual } from 'react-redux'; import { useEffect, useCallback, useMemo } from 'react'; import { loadWatchlist, toggleWatchlist as toggleWatchlistAction } from '../../../../../store/slices/stockSlice'; import { message } from 'antd'; @@ -15,7 +15,7 @@ export const useWatchlist = () => { const dispatch = useDispatch(); // 从 Redux 获取自选股列表 - const watchlistArray = useSelector(state => state.stock.watchlist); + const watchlistArray = useSelector(state => state.stock.watchlist, shallowEqual); const loading = useSelector(state => state.stock.loading.watchlist); // 转换为 Set 方便快速查询