Skip to content

Commit

Permalink
fix: should not pass loadData when expandedKeys is not changed, whi…
Browse files Browse the repository at this point in the history
…ck avoid triggering all nodes load data
  • Loading branch information
bbb169 committed Oct 14, 2024
1 parent de83565 commit 91d4cac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
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])

// ========================== Render ==========================
if (memoTreeData.length === 0) {
return (
Expand Down Expand Up @@ -237,7 +247,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
showIcon={showTreeIcon}
switcherIcon={switcherIcon}
showLine={treeLine}
loadData={searchValue ? null : (loadData as any)}
loadData={loadDataFun}
motion={treeMotion}
activeKey={activeKey}
// We handle keys by out instead tree self
Expand Down

0 comments on commit 91d4cac

Please sign in to comment.