Skip to content

Commit

Permalink
feat: 优化loadDataFun变化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
bbb169 committed Oct 21, 2024
1 parent ce94a41 commit 71f018a
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, 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) {
Expand Down

0 comments on commit 71f018a

Please sign in to comment.