Command Palette

Search for a command to run...

Hectal
Phase 8: Refs and the DOM
React · Exercise 1 of 6Next
Beginner

Focus the field from a button

Clicking the Edit name button (id="edit") must put the cursor in the name input (id="name").

Use useRef: attach the ref to the input and call focus() on it in the button's click handler.

What Check tests

  1. The input and the button are on the page
  2. The input is not focused before the click
  3. Clicking Edit name focuses the input
  4. Uses useRef

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.