5 hands-on exercises and 5 find-the-bug challenges for the useRef Explained lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Use a ref to read the input's value on click.
Keep a counter in a ref and show it when asked.
Use a ref to read the heading's text.
Record the initial value in a ref and show it.
Focus the field from a button using a ref.
The ref is created but never given to the element.
A ref holds its value under current.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceChanging a ref does not re-render, so the display never updates.
Assign the ref in an effect, after the render has happened.
The ref points at the button rather than the input.