OTP auto foucs (React js)

Hi everyone, I would like to implment OTP verification and it has 4 inputs, and I want if the user enter a number for the first input, it will auto foucs to the second input and so on.
3 Replies
Senra
Senra10mo ago
tried using useRef? just give the onInput attribute of one input a value of input2Ref.current.focus()
serkan
serkan10mo ago
the code from the updated version is working, https://stackoverflow.com/a/54225169
Stack Overflow
How to set focus on an input field after rendering?
What's the react way of setting focus on a particular text field after the component is rendered? Documentation seems to suggest using refs, e.g: Set ref="nameInput" on my input field in the render
wmh_
wmh_10mo ago
It worked for me, thank you guys👍