useRef()
Use useRef()
to get a hold of DOM elements created by the component.
There are two parts to retrieving a DOM element reference:
useRef()
returns aref
object that contains acurrent
property which will eventually contain the reference.ref={_ref_variable_}
is a prop binding that will set thecurrent
property of theref
object to the DOM element.
Example
The example on the right uses useRef()
to get a reference to the input
element. However, it is missing the ref
prop binding. Add the ref
prop binding to make the example work as expected