From 46663471b152ada9f51adac676fc2144584083c4 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 22:07:48 +0800 Subject: [PATCH] fix: sync load logic --- src/OptionList.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index d21cf5cb..d8ff001f 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -242,15 +242,15 @@ const OptionList: React.ForwardRefRenderFunction = (_, onKeyUp: () => {}, })); - const syncLoadData = useEvent(loadData); - - const loadDataFun = useMemo( - () => (searchValue ? null : (syncLoadData as any)), + const hasLoadDataFn = useMemo( + () => (searchValue ? false : true), [searchValue, treeExpandedKeys || expandedKeys], ([preSearchValue], [nextSearchValue, nextExcludeSearchExpandedKeys]) => preSearchValue !== nextSearchValue && !!(nextSearchValue || nextExcludeSearchExpandedKeys), ); + const syncLoadData = hasLoadDataFn ? loadData : null; + // ========================== Render ========================== if (memoTreeData.length === 0) { return ( @@ -292,7 +292,7 @@ const OptionList: React.ForwardRefRenderFunction = (_, showIcon={showTreeIcon} switcherIcon={switcherIcon} showLine={treeLine} - loadData={loadDataFun} + loadData={syncLoadData} motion={treeMotion} activeKey={activeKey} // We handle keys by out instead tree self