React Dojo

Search

Search concepts, exercises and quizzes

practicebasic

Focus and silent counter

The input must focus on mount and when pressing 'Focus'. Also, count how many times the component re-rendered without causing additional re-renders.


Objectives

  1. 1.Create a ref for the input and focus it on mount
  2. 2.Focus button that applies programmatic focus
  3. 3.Keep a render counter in another ref — must NOT cause re-renders
  4. 4.The input text is controlled state
  5. 5.Clear button resets the text and the input
your code
Hint

useRef.current persists between renders without triggering them. useState does trigger them. Use each where it belongs.

Related concepts

Was this helpful?
Sign in to give feedback