I have an object array like this( in Reactjs functional component) which has this guys :
--------comments (6) [{…}, {…}, {…}, {…}, {…}, {…}]
0(pin):{comment:'1',commentid:264}
1(pin):{comment:'2',commentid:265}
2(pin):{comment:'5',commentid:266}
3(pin):{comment:'1',commentid:267}
4(pin):{comment:'2',commentid:268}
5(pin):{comment:'test',commentid:269}
I have them displayed on page. I want to get id of the object i click. Here is my function.
const deleteComment = (id : Number) => {
console.log('--------id', id);
}
I tried to do map,filter or foreach but nothing worked,any suggestions please?
<ul>
{
comments.map((items: any) => {
return (
<p
key={uuidv4()}
>Comment : {items.comment}
<button onClick={() => {deleteComment(items.commentid)}}>Delete</button>
</p>
);
})}
</ul>
Update (I restarted the app and everything works fine now)