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
- The input and the button are on the page
- The input is not focused before the click
- Clicking Edit name focuses the input
- 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.