A DOM reference lets a React component hold a program-accessible reference to an element it renders. useRef supplies the reference without causing a re-render when its value changes. section 7.1.3
Focusing an input
Create a ref, attach it to the input, and access the rendered element through ref.current: useEffect(() => ref.current.focus(), []). section 7.1.3
Use a DOM reference when a component needs to:
- Address a rendered DOM element through script. section 7.1.3
- Read or update ref.current without triggering a new render. section 7.1.3
Figure 7.1 As the user clicks the button, the execution bifurcates based on whether this click happens within a very short time of the last recorded click.
Use the related listings to compare a ref attached to a DOM element with a ref used to retain an internal value. section 7.1.3
