From 71f018acddb98773ed71980e903353abd48d14e8 Mon Sep 17 00:00:00 2001 From: jingzouzou <827088092@qq.com> Date: Mon, 21 Oct 2024 13:06:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96loadDataFun=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OptionList.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 939b1e3d..547b3b05 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -196,14 +196,25 @@ const OptionList: React.ForwardRefRenderFunction = (_, onKeyUp: () => {}, })); - const loadDataFun = React.useMemo(() => { - // should not pass `loadData` when expandedKeys is not changed - if (!searchValue && searchExpandedKeys?.length && !mergedExpandedKeys) { - return null; - } - - return searchValue ? null : (loadData as any); - }, [searchValue, searchExpandedKeys?.length, mergedExpandedKeys, loadData]); + const loadDataFun = useMemo( + () => { + return searchValue ? null : (loadData as any); + }, + [searchValue, mergedExpandedKeys], + (pre, next) => { + const [preSearchValue] = pre; + const [nextSearchValue, nextMergedExpandedKeys] = next; + + if (preSearchValue !== nextSearchValue) { + // should not pass `loadData` when expandedKeys is not changed + if (!nextSearchValue && !nextMergedExpandedKeys) { + return false; + } + return true; + } + return false; + }, + ); // ========================== Render ========================== if (memoTreeData.length === 0) {