From 6b767b18f1c4d27add211f84763e85ae3096160b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 21 Nov 2024 21:50:23 +0800 Subject: [PATCH] fix: off topic --- src/OptionList.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 04c0f27b..d21cf5cb 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -10,6 +10,7 @@ import LegacyContext from './LegacyContext'; import TreeSelectContext from './TreeSelectContext'; import type { Key, SafeKey } from './interface'; import { getAllKeys, isCheckDisabled } from './utils/valueUtil'; +import { useEvent } from 'rc-util'; const HIDDEN_STYLE = { width: 0, @@ -241,17 +242,13 @@ const OptionList: React.ForwardRefRenderFunction = (_, onKeyUp: () => {}, })); + const syncLoadData = useEvent(loadData); + const loadDataFun = useMemo( - () => (searchValue ? null : (loadData as any)), - [loadData, searchValue, treeExpandedKeys || expandedKeys], - ( - [prevLoadData, preSearchValue], - [nextLoadData, nextSearchValue, nextExcludeSearchExpandedKeys], - ) => - // `loadData` changed - prevLoadData !== nextLoadData || - // `searchValue` changed and not in search mode - (preSearchValue !== nextSearchValue && !!(nextSearchValue || nextExcludeSearchExpandedKeys)), + () => (searchValue ? null : (syncLoadData as any)), + [searchValue, treeExpandedKeys || expandedKeys], + ([preSearchValue], [nextSearchValue, nextExcludeSearchExpandedKeys]) => + preSearchValue !== nextSearchValue && !!(nextSearchValue || nextExcludeSearchExpandedKeys), ); // ========================== Render ==========================