Skip to content

Commit 46feab9

Browse files
committed
Replace usage of findDOMNode with createRef
1 parent 8e94e61 commit 46feab9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/DOMWrap.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
32
import ResizeObserver from 'resize-observer-polyfill';
43
import SubMenu from './SubMenu';
54
import { getWidth, setStyle, menuAllProps } from './util';
@@ -52,10 +51,12 @@ class DOMWrap extends React.Component<DOMWrapProps, DOMWrapState> {
5251
lastVisibleIndex: undefined,
5352
};
5453

54+
childRef = React.createRef<HTMLElement>();
55+
5556
componentDidMount() {
5657
this.setChildrenWidthAndResize();
5758
if (this.props.level === 1 && this.props.mode === 'horizontal') {
58-
const menuUl = ReactDOM.findDOMNode(this) as HTMLElement;
59+
const menuUl = this.childRef.current;
5960
if (!menuUl) {
6061
return;
6162
}
@@ -109,7 +110,7 @@ class DOMWrap extends React.Component<DOMWrapProps, DOMWrapState> {
109110
// get all valid menuItem nodes
110111
getMenuItemNodes = (): HTMLElement[] => {
111112
const { prefixCls } = this.props;
112-
const ul = ReactDOM.findDOMNode(this) as HTMLElement;
113+
const ul = this.childRef.current;
113114
if (!ul) {
114115
return [];
115116
}
@@ -192,7 +193,7 @@ class DOMWrap extends React.Component<DOMWrapProps, DOMWrapState> {
192193
if (this.props.mode !== 'horizontal') {
193194
return;
194195
}
195-
const ul = ReactDOM.findDOMNode(this) as HTMLElement;
196+
const ul = this.childRef.current;
196197

197198
if (!ul) {
198199
return;
@@ -247,7 +248,7 @@ class DOMWrap extends React.Component<DOMWrapProps, DOMWrapState> {
247248
return;
248249
}
249250

250-
const ul = ReactDOM.findDOMNode(this) as HTMLElement;
251+
const ul = this.childRef.current;
251252
if (!ul) {
252253
return;
253254
}
@@ -360,7 +361,11 @@ class DOMWrap extends React.Component<DOMWrapProps, DOMWrapState> {
360361

361362
const Tag = tag as any;
362363

363-
return <Tag {...rest}>{this.renderChildren(children)}</Tag>;
364+
return (
365+
<Tag ref={this.childRef} {...rest}>
366+
{this.renderChildren(children)}
367+
</Tag>
368+
);
364369
}
365370
}
366371

0 commit comments

Comments
 (0)