Skip to content

Commit 71f018a

Browse files
committed
feat: 优化loadDataFun变化逻辑
1 parent ce94a41 commit 71f018a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/OptionList.tsx

+19-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,25 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
196196
onKeyUp: () => {},
197197
}));
198198

199-
const loadDataFun = React.useMemo(() => {
200-
// should not pass `loadData` when expandedKeys is not changed
201-
if (!searchValue && searchExpandedKeys?.length && !mergedExpandedKeys) {
202-
return null;
203-
}
204-
205-
return searchValue ? null : (loadData as any);
206-
}, [searchValue, searchExpandedKeys?.length, mergedExpandedKeys, loadData]);
199+
const loadDataFun = useMemo(
200+
() => {
201+
return searchValue ? null : (loadData as any);
202+
},
203+
[searchValue, mergedExpandedKeys],
204+
(pre, next) => {
205+
const [preSearchValue] = pre;
206+
const [nextSearchValue, nextMergedExpandedKeys] = next;
207+
208+
if (preSearchValue !== nextSearchValue) {
209+
// should not pass `loadData` when expandedKeys is not changed
210+
if (!nextSearchValue && !nextMergedExpandedKeys) {
211+
return false;
212+
}
213+
return true;
214+
}
215+
return false;
216+
},
217+
);
207218

208219
// ========================== Render ==========================
209220
if (memoTreeData.length === 0) {

0 commit comments

Comments
 (0)