findDOMNode()

Use callback refs over findDOMNode()

Note: React also supports using a string (instead of a callback) as a ref prop on any component, although this approach is mostly legacy at this point.

findDOMNode(this)

Before:

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

  render() {
    return <div />
  }
}

After

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

  render() {
    return <div ref={node => this.node = node}/>
  }
}

findDOMNode(stringDOMRef)

Before

After

findDOMNode(childComponentStringRef)

Before:

After

Last updated