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

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

Closed
feross opened this issue Oct 28, 2020 · 1 comment
Closed

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

feross opened this issue Oct 28, 2020 · 1 comment

Comments

@feross
Copy link
Member

feross commented Oct 28, 2020

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} />
  }
}
@jondavidjohn
Copy link

This is unfortunate, if you're using a third party library that does not expose the ref you are after you are left with no choice.

jsx-eslint/eslint-plugin-react#678 (comment) explains this perfectly.

And the response is that you should disable it per line with a comment, which is not possible with standard.

jsx-eslint/eslint-plugin-react#678 (comment)

This leaves me being blocked because I'm using standard. If a third party library doesn't provide an adequate API I have to remove my linter?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants