Skip to content

Commit 91d4cac

Browse files
committed
fix: should not pass loadData when expandedKeys is not changed, whick avoid triggering all nodes load data
1 parent de83565 commit 91d4cac

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: src/OptionList.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
196196
onKeyUp: () => {},
197197
}));
198198

199+
200+
const loadDataFun = React.useMemo(() => {
201+
// should not pass `loadData` when expandedKeys is not changed
202+
if (!searchValue && searchExpandedKeys?.length && !mergedExpandedKeys) {
203+
return null
204+
}
205+
206+
return searchValue ? null : (loadData as any)
207+
}, [searchValue])
208+
199209
// ========================== Render ==========================
200210
if (memoTreeData.length === 0) {
201211
return (
@@ -237,7 +247,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
237247
showIcon={showTreeIcon}
238248
switcherIcon={switcherIcon}
239249
showLine={treeLine}
240-
loadData={searchValue ? null : (loadData as any)}
250+
loadData={loadDataFun}
241251
motion={treeMotion}
242252
activeKey={activeKey}
243253
// We handle keys by out instead tree self

0 commit comments

Comments
 (0)