I'm planning to set to autofocus the last element of the array by using a ref
, but I don't know how to do it since I'm already using ref
for react-hook-form
I've been to this link, but I don't know how to apply it in my case. How can I use multiple refs for an array of elements with hooks?,
Somebody knows how to inject this two ref
s to one input?
Here's my ref
to auto focus an input
const [inputRef, setInputRef] = useFocus();
And here's my current codes with react-form-hook's ref:
{[...Array(10)].map((x, i) => (
<input
type="text"
name="book"
className="border mr-px-5"
ref={register(rules.book)}
ref={lastElement ? inputRef : null} // conditional focus ref
/>
)}