Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: always change treeProps.expandedKeys to avoid wrong loadling data #576

Merged
merged 13 commits into from
Oct 24, 2024
Next Next commit
fix: should not pass loadData when expandedKeys is not changed, whi…
…ck avoid triggering all nodes load data
bbb169 committed Oct 14, 2024
commit 91d4caca7b7d08c5316d2c54726a55b98cbc0c9c
12 changes: 11 additions & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
@@ -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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}, [searchValue])
}, [searchValue, searchExpandedKeys, mergedExpandedKeys]);


// ========================== Render ==========================
if (memoTreeData.length === 0) {
return (
@@ -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