mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Add deprecation warning for findDOMNode
This is removed in version 19. We already warned inside of Strict Mode but this adds the warning everywhere.
This commit is contained in:
2 files changed
+14
-1
No files matched your search
+12
@@ -238,10 +238,22 @@ function legacyRenderSubtreeIntoContainer(
|
||||
return getPublicRootInstance(root);
|
||||
}
|
||||
|
||||
let didWarnAboutFindDOMNode = false;
|
||||
|
||||
export function findDOMNode(
|
||||
componentOrElement: Element | ?React$Component<any, any>,
|
||||
): null | Element | Text {
|
||||
if (__DEV__) {
|
||||
if (!didWarnAboutFindDOMNode) {
|
||||
didWarnAboutFindDOMNode = true;
|
||||
console.error(
|
||||
'findDOMNode is deprecated and will be removed in the next major ' +
|
||||
'release. Instead, add a ref directly to the element you want ' +
|
||||
'to reference. Learn more about using refs safely here: ' +
|
||||
'https://reactjs.org/link/strict-mode-find-node',
|
||||
);
|
||||
}
|
||||
|
||||
const owner = (ReactCurrentOwner.current: any);
|
||||
if (owner !== null && owner.stateNode !== null) {
|
||||
const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
|
||||
|
||||
@@ -31,7 +31,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
|
||||
'uses the legacy childContextTypes API which is no longer supported and will be removed'
|
||||
) !== -1 ||
|
||||
format.indexOf('ReactDOMTestUtils is deprecated') !== -1 ||
|
||||
format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1
|
||||
format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1 ||
|
||||
format.indexOf('findDOMNode is deprecated and will be removed') !== -1
|
||||
) {
|
||||
// This is a backported warning. In `main`, there's a different warning
|
||||
// (and it's fully tested). Not going to bother upgrading all the tests
|
||||
|
||||
Reference in new issue
Block a user