I am currently learning React with Typescript and have come across an issue with handling event with the onClick property. I have a react component of a list of stuff from an array and I want to log into the console the item I clicked. It worked when I was referencing the item inline. I was trying to test how it would work if I moved the logic outside to a function and then having onClick reference the function. This is what I have:
When i do console.log("Clicked, event.currentTarget); it just shows that I clicked the list object, but say for example if I clicked New York I want the console to say "Clicked New York" and not an object with its list of properties. Before I would just have
"<li className="list-group-item" key={item} onClick={() => console.log("Clicked", item)}>;"
and it worked. I tried inspecting the object to see what properties it would have to maybe use the . operator to reference one of them to get the actual item in the array, but I couldn't find anything in the console. Is there a way to actually get the item in the array while using a function to handle the event like I have and if so what would have to be passed as the argument? I was just thinking that this may be necessary for complicated logic while also needing the name of the item in the array that is clicked. I have looked through posts on this topic and can't seem to find one.