no-find-dom-node
Disallows 'findDOMNode'.
Full Name in eslint-plugin-react-dom
react-dom/no-find-dom-nodeFull Name in @eslint-react/eslint-plugin
@eslint-react/dom-no-find-dom-nodePresets
dom
recommended
recommended-typescript
recommended-type-checked
strict
strict-typescript
strict-type-checked
Rule Details
This API will be removed in a future major version of React. See the alternatives.
Examples
Using findDOMNode to access a DOM node
findDOMNode is a legacy API that will be removed. Use refs instead to reliably access DOM nodes.
// Problem: findDOMNode is deprecated and will be removed.
import React, { Component } from "react";
import { findDOMNode } from "react-dom";
class AutoSelectingInput extends Component {
componentDidMount() {
const input = findDOMNode(this);
// ^^^ 'findDOMNode' will be removed in a future version of React. Use the alternatives instead.
if (input instanceof HTMLInputElement) {
input.select();
}
}
render() {
return <input defaultValue="Hello" />;
}
}// Recommended: use createRef to access the underlying DOM node.
import React, { Component } from "react";
class AutoSelectingInput extends Component {
inputRef = React.createRef<HTMLInputElement>();
componentDidMount() {
const input = this.inputRef.current;
input?.select();
}
render() {
return <input ref={this.inputRef} defaultValue="Hello" />;
}
}Using findDOMNode in a function component
findDOMNode is also problematic in function components because it relies on the component instance (this), which does not exist in function components.
// Problem: findDOMNode is deprecated and does not work well with function components.
import { useEffect } from 'react';
import { findDOMNode } from 'react-dom';
function AutoSelectingInput() {
useEffect(() => {
const input = findDOMNode(this);
input.select();
}, []);
return <input defaultValue="Hello" />;
}// Recommended: use useRef to access the underlying DOM node.
import { useEffect, useRef } from 'react';
function AutoSelectingInput() {
const ref = useRef(null);
useEffect(() => {
ref.current.select();
}, []);
return <input ref={ref} defaultValue="Hello" />;
}Versions
Resources
Further Reading
See Also
react-dom/no-hydrate
Replaces usage ofReactDOM.hydrate()withhydrateRoot().react-dom/no-render
Replaces usage ofReactDOM.render()withcreateRoot(node).render().