React Refs are a useful feature that acts as a means to reference a DOM element or a class component from within a parent component.
We can get more idea by looking below example. you can put this file in /src/components folder and put
In above code, in constructor we create a ref and assign it to inputRef. now inputRef given to input element ref. While run this code, It will show focused on textbox and one object in console panel, which have our textbox. now, type something in textbox and click on button shows value of textbox in alert.
Now we will understand by parent and child components
2. RefReact - Child component
In above code, focusInput is a method in RefReact - child component which is called from parent component by using componentRef. When we click on button it will focus the textbox.