@@ -62,6 +62,7 @@ export interface ITreeProps {
62
62
className ?: string ;
63
63
draggable ?: boolean ;
64
64
expandKeys ?: UniqueId [ ] ;
65
+ loadedKeys ?: string [ ] ;
65
66
activeKey ?: UniqueId ;
66
67
onExpand ?: ( expandedKeys : React . Key [ ] , node : ITreeNodeItemProps ) => void ;
67
68
onSelect ?: ( node : ITreeNodeItemProps , isUpdate ?) => void ;
@@ -83,6 +84,7 @@ const TreeView = ({
83
84
className,
84
85
data = [ ] ,
85
86
draggable = false ,
87
+ loadedKeys,
86
88
expandKeys : controlExpandKeys ,
87
89
activeKey : controlActiveKey ,
88
90
onExpand,
@@ -95,7 +97,6 @@ const TreeView = ({
95
97
} : ITreeProps ) => {
96
98
const [ expandKeys , setExpandKeys ] = useState < UniqueId [ ] > ( [ ] ) ;
97
99
const [ activeKey , setActiveKey ] = useState < string | null > ( null ) ;
98
- const loadDataCache = useRef < Record < string , boolean > > ( { } ) ;
99
100
const [ loadingKeys , setLoadingKeys ] = useState < string [ ] > ( [ ] ) ;
100
101
const dragOverNode = useRef < ITreeNodeItemProps > ( ) ;
101
102
const dragInfo = useRef < {
@@ -108,7 +109,7 @@ const TreeView = ({
108
109
109
110
const canLoadData = ( key : string ) => {
110
111
if ( ! onLoadData ) return false ;
111
- if ( loadDataCache . current . hasOwnProperty ( key ) ) return false ;
112
+ if ( loadedKeys ?. includes ( key ) ) return false ;
112
113
return true ;
113
114
} ;
114
115
@@ -120,7 +121,6 @@ const TreeView = ({
120
121
nextKeys . push ( uuid ! ) ;
121
122
return nextKeys ;
122
123
} ) ;
123
- loadDataCache . current [ uuid ] = true ;
124
124
onLoadData ! ( node ) . finally ( ( ) => {
125
125
setLoadingKeys ( ( keys ) => {
126
126
const nextKeys = keys . concat ( ) ;
0 commit comments