Showing posts with label findDOMNode. Show all posts
Showing posts with label findDOMNode. Show all posts

Sunday, April 22, 2018

What is ReactDOM.findDOMNode

In React refs can be used to access DOM elements and other child components in the page. We use ReactDOM.findDOMNode to get the instance of other react components in the page. Once we get the instance we can access the components.

In this example we have 2 components HelloRefComponent is the parent component and HelloChildComponent is the child component. We create a ref (ref="refComponent") to the child component and use it in the parent component to set the focus on the child component. We use ReactDOM.findDOMNode to get the instance of the child component and set the focus.

ReactDOM.findDOMNode(this.refs.refComponent)