Categories

Jul 2, 2019 in React JS

Q:

Which is preferred option with in callback refs and findDOMNode()?

1 Answer

Jul 2, 2019

It is preferred to use callback refs over findDOMNode() API. Because findDOMNode() prevents certain improvements in React in the future.

The legacy approach of using findDOMNode:

class MyComponent extends Component {
  componentDidMount() {
    findDOMNode(this).scrollIntoView()
  }

  render() {
    return <div />
  }
}

The recommended approach is:

class MyComponent extends Component {
  componentDidMount() {
    this.node.scrollIntoView()
  }

  render() {
    return <div ref={node => this.node = node} />
  }
}
Click here to read more about React JS
Click here to read more about Insurance

Related questions

Madanswer
Jul 2, 2019 in React JS
Jun 19 in React JS
Jul 2, 2019 in React JS
...