@@ -53,6 +53,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
53
53
...others
54
54
} = props ;
55
55
const [ activeData , setActiveData ] = useState < ITreeNodeItem > ( { } ) ;
56
+ const [ activeId , setActiveId ] = useState < any > ( '' ) ;
56
57
const [ expandedKeys , setExpandedKeys ] = useState < any [ ] > ( [ ] ) ;
57
58
const inputRef = useRef < any > ( null ) ;
58
59
@@ -132,6 +133,11 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
132
133
}
133
134
return contextMenu ;
134
135
} ;
136
+ /**
137
+ * TODO:
138
+ * useEffect 约束参数最好不要为引用类型
139
+ * 这里 data 要做细粒度判断
140
+ */
135
141
useEffect ( ( ) => {
136
142
const { contextMenu, id, type } = activeData ;
137
143
const moContextMenu : IMenuItem [ ] =
@@ -147,7 +153,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
147
153
return function cleanup ( ) {
148
154
contextViewMenu ?. dispose ( ) ;
149
155
} ;
150
- } , [ data , activeData ] ) ;
156
+ } , [ data , activeId ] ) ;
151
157
152
158
const onDrop = ( info ) => {
153
159
console . log ( info ) ;
@@ -253,6 +259,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
253
259
switcherIcon = { < Icon type = "chevron-right" /> }
254
260
onRightClick = { ( { event, node } : any ) => {
255
261
setActiveData ( node . data ) ;
262
+ setActiveId ( node . data . id )
256
263
} }
257
264
onExpand = { ( expandedKeys ) => {
258
265
setExpandedKeys ( expandedKeys )
0 commit comments