Skip to content

Commit

Permalink
fix: sync load logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 21, 2024
1 parent 6b767b1 commit 4666347
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
onKeyUp: () => {},
}));

const syncLoadData = useEvent(loadData);

const loadDataFun = useMemo(
() => (searchValue ? null : (syncLoadData as any)),
const hasLoadDataFn = useMemo(
() => (searchValue ? false : true),
[searchValue, treeExpandedKeys || expandedKeys],
([preSearchValue], [nextSearchValue, nextExcludeSearchExpandedKeys]) =>
preSearchValue !== nextSearchValue && !!(nextSearchValue || nextExcludeSearchExpandedKeys),
);

const syncLoadData = hasLoadDataFn ? loadData : null;

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

0 comments on commit 4666347

Please sign in to comment.