Skip to content
Rung

10/12

No. 10Medium15 min

useRef: DOM Access & Persistence

Mission

Use useRef to reach DOM elements directly and to keep values that survive renders without causing new ones.

Tasks

  1. 1

    Create a ref with useRef(null) and attach it to the <input> with the ref attribute.

  2. 2

    Make the first button focus the input using the ref (.focus()).

  3. 3

    Create a second ref that starts at 0 to count clicks on the 'secret' button.

  4. 4

    Increase that count on every click without using useState.

  5. 5

    Report the count with an alert or console.log, not on screen.