Skip to content

Commit

Permalink
feat: optimize loadDataFun's calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bbb169 committed Oct 21, 2024
1 parent ce94a41 commit 8acc1c8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,25 @@ 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, searchExpandedKeys?.length, mergedExpandedKeys, loadData]);
const loadDataFun = useMemo(
() => {
return searchValue ? null : (loadData as any);
},
[searchValue, treeExpandedKeys || expandedKeys],
(pre, next) => {
const [preSearchValue] = pre;
const [nextSearchValue, nextExcludeSearchExpandedKeys] = next;

if (preSearchValue !== nextSearchValue) {
// should not pass `loadData` when expandedKeys is not changed
if (!nextSearchValue && !nextExcludeSearchExpandedKeys) {
return false;
}
return true;
}
return false;
},
);

// ========================== Render ==========================
if (memoTreeData.length === 0) {
Expand Down

0 comments on commit 8acc1c8

Please sign in to comment.