Hi I have the below code, in which I am trying to get the value inside list using when a person clicks on the button wrapped inside that is inside list element. I tried using UseRef but it is returning all the listed items, but In my case I only want to target the value that is associated with that button. Here is my current approach.
const tabRef = useRef();
function addButtonHandler() {
console.log(tabRef.current.innerText);
}
<ul ref={tabRef}>
<li >
<button onClick={addButtonHandler}></button>
Some context here.</li>
<li >
<button onClick={addButtonHandler}"></button>
More context here.</li>
<li >
<button onClick={addButtonHandler}></button>
even more context here.</li>
</ul>