Skip to content

Commit 8432c46

Browse files
committed
fix: contextmenu trigger fix
contextmenu trigger fix
1 parent 293d0ee commit 8432c46

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/tree/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
5353
...others
5454
} = props;
5555
const [activeData, setActiveData] = useState<ITreeNodeItem>({});
56+
const [activeId, setActiveId] = useState<any>('');
5657
const [expandedKeys, setExpandedKeys] = useState<any[]>([]);
5758
const inputRef = useRef<any>(null);
5859

@@ -132,6 +133,11 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
132133
}
133134
return contextMenu;
134135
};
136+
/**
137+
* TODO:
138+
* useEffect 约束参数最好不要为引用类型
139+
* 这里 data 要做细粒度判断
140+
*/
135141
useEffect(() => {
136142
const { contextMenu, id, type } = activeData;
137143
const moContextMenu: IMenuItem[] =
@@ -147,7 +153,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
147153
return function cleanup() {
148154
contextViewMenu?.dispose();
149155
};
150-
}, [data, activeData]);
156+
}, [data, activeId]);
151157

152158
const onDrop = (info) => {
153159
console.log(info);
@@ -253,6 +259,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
253259
switcherIcon={<Icon type="chevron-right" />}
254260
onRightClick={({ event, node }: any) => {
255261
setActiveData(node.data);
262+
setActiveId(node.data.id)
256263
}}
257264
onExpand={(expandedKeys) => {
258265
setExpandedKeys(expandedKeys)

0 commit comments

Comments
 (0)