logoESLint React
Rules

no-find-dom-node

Disallows 'findDOMNode'.

Full Name in eslint-plugin-react-dom

react-dom/no-find-dom-node

Full Name in @eslint-react/eslint-plugin

@eslint-react/dom-no-find-dom-node

Presets

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.

Common Violations

Invalid

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" />;
  }
}

Valid

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" />;
  }
}

Resources

Further Reading


See Also

On this page