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) {