Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RootRef] Deprecate component #24075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/pages/api-docs/root-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function MyComponent() {
}
```

@deprecated



## Props
Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/RootRef/RootRef.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface RootRefProps<T = any> {
* );
* }
* ```
*
* @deprecated
* API:
*
* - [RootRef API](https://material-ui.com/api/root-ref/)
Expand Down
17 changes: 17 additions & 0 deletions packages/material-ui/src/RootRef/RootRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import { exactProp, refType } from '@material-ui/utils';
import setRef from '../utils/setRef';

let warnedOnce = false;

/**
* ⚠️⚠️⚠️
* If you want the DOM element of a Material-UI component check out
Expand Down Expand Up @@ -35,6 +37,8 @@ import setRef from '../utils/setRef';
* );
* }
* ```
*
* @deprecated
*/
class RootRef extends React.Component {
componentDidMount() {
Expand All @@ -61,6 +65,19 @@ class RootRef extends React.Component {
}

render() {
if (process.env.NODE_ENV !== 'production') {
if (!warnedOnce) {
warnedOnce = true;
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'),
);
}
}

return this.props.children;
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/material-ui/src/RootRef/RootRef.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { spy } from 'sinon';
import { consoleWarnMock } from 'test/utils/consoleErrorMock';
import createMount from 'test/utils/createMount';
import RootRef from './RootRef';

Expand All @@ -11,6 +12,14 @@ describe('<RootRef />', () => {
// StrictModeViolation: uses findDOMNode
const mount = createMount({ strict: false });

beforeEach(() => {
consoleWarnMock.spy();
});

afterEach(() => {
consoleWarnMock.reset();
});

it('call rootRef function on mount and unmount', () => {
const rootRef = spy();
const wrapper = mount(
Expand Down