Skip to content

Prevent usage of findDOMNode (react/no-find-dom-node) #1570

Closed
@feross

Description

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md

Facebook will eventually deprecate findDOMNode as it blocks certain improvements in React in the future.

It is recommended to use callback refs instead. See Dan Abramov comments and examples.

Rule Details

Examples of incorrect code for this rule:

class MyComponent extends Component {
  componentDidMount() {
    findDOMNode(this).scrollIntoView();
  }
  render() {
    return <div />
  }
}

Examples of correct code for this rule:

class MyComponent extends Component {
  componentDidMount() {
    this.node.scrollIntoView();
  }
  render() {
    return <div ref={node => this.node = node} />
  }
}

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions