{arr.map((i) => { // arr = [1,2,3,4,5], taRef=useRef()
return (
<div key={i}>
<textarea ref={taRef} placeholder="Enter comment" rows={5} />
<button onClick={setFocus}>Set Focus</button>
</div>
);
})}
I want to set focus on the corresponding textarea element when ever I click on the corresponding button. Right now it is always setting the focus on the last element.
Check the sandbox example here