1 | import * as React from 'react';
|
2 | import * as ReactDOM from 'react-dom';
|
3 | import PropTypes from 'prop-types';
|
4 | import { exactProp, refType } from '@material-ui/utils';
|
5 | import setRef from '../utils/setRef';
|
6 | let warnedOnce = false;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | class RootRef extends React.Component {
|
43 | componentDidMount() {
|
44 | this.ref = ReactDOM.findDOMNode(this);
|
45 | setRef(this.props.rootRef, this.ref);
|
46 | }
|
47 |
|
48 | componentDidUpdate(prevProps) {
|
49 | const ref = ReactDOM.findDOMNode(this);
|
50 |
|
51 | if (prevProps.rootRef !== this.props.rootRef || this.ref !== ref) {
|
52 | if (prevProps.rootRef !== this.props.rootRef) {
|
53 | setRef(prevProps.rootRef, null);
|
54 | }
|
55 |
|
56 | this.ref = ref;
|
57 | setRef(this.props.rootRef, this.ref);
|
58 | }
|
59 | }
|
60 |
|
61 | componentWillUnmount() {
|
62 | this.ref = null;
|
63 | setRef(this.props.rootRef, null);
|
64 | }
|
65 |
|
66 | render() {
|
67 | if (process.env.NODE_ENV !== 'production') {
|
68 | if (!warnedOnce) {
|
69 | warnedOnce = true;
|
70 | console.warn(['Material-UI: The RootRef component is deprecated.', 'The component relies on the ReactDOM.findDOMNode API which is deprecated in React.StrictMode.', 'Instead, you can get a reference to the underlying DOM node of the components via the `ref` prop.'].join('/n'));
|
71 | }
|
72 | }
|
73 |
|
74 | return this.props.children;
|
75 | }
|
76 |
|
77 | }
|
78 |
|
79 | process.env.NODE_ENV !== "production" ? RootRef.propTypes = {
|
80 | |
81 |
|
82 |
|
83 | children: PropTypes.element.isRequired,
|
84 |
|
85 | |
86 |
|
87 |
|
88 | rootRef: refType.isRequired
|
89 | } : void 0;
|
90 |
|
91 | if (process.env.NODE_ENV !== 'production') {
|
92 | process.env.NODE_ENV !== "production" ? RootRef.propTypes = exactProp(RootRef.propTypes) : void 0;
|
93 | }
|
94 |
|
95 | export default RootRef; |
\ | No newline at end of file |