U
U
Username2018-08-08 11:18:06
React
Username, 2018-08-08 11:18:06

How to make an input field active when clicking on another element?

Good afternoon!
I am writing a universal TextField component that can be used on application pages.
Task: when clicking on the pencil icon , it is necessary to make the input field active i.e. focus.
Solution: hang ref on the input field, make ref unique for each field.
But this solution seems clumsy to me, maybe there are more concise methods?
Working example: https://codesandbox.io/s/rrjvjy5qp4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-08
@dalv_happy

Solution: hang ref on input field

Good decision.
It makes no sense. Use one ref in the TextField component, it will be unique in each created instance of the component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question