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.Create a ref for the input and focus it on mount
- 2.
Focusbutton that applies programmatic focus - 3.Keep a render counter in another ref — must NOT cause re-renders
- 4.The input text is controlled state
- 5.
Clearbutton 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
