I am trying to delete a Person
object from my table on the server using PersonId
and a url
. First I show the list of Person
objects and next to each object I have a delete-button
to delete the object. I am trying to pass the value of PersonId
to the method removePerson(person)
. I am using this method as test to show the PersonId
to the console, but I am getting this error: Uncaught TypeError: Cannot read property 'removePerson' of undefined
. This is my code:
return (
<table id="myTable">
<thead>
<tr>
<th>Person id</th>
<th>Person name</th>
<th>Person Surname</th>
<th>Action </th>
</tr>
</thead>
<tbody>
{this.props.persons.map(function(person , i) {
return(
<tr key={i}>
<td>{person.PersontId}</td>
<td>{person.Name}</Link></td>
<td>{person.Surname}</td>
<td> <button className="btn btn-primary btn-xs" onClick={()=>this.removePerson({person})}
>Delete</button></td>
</tr>
);
})}
</tbody>
</table>
The method I use as a test is:
removePerson(person) {
console.log(person.PersonId); //Just a test to catch PersonId
}
But if I change onClick={()=>this.removePerson({person})}
with onClick={()=>console.log({project})}
I get the Person
object to the console each time I click on Delete
-button.
Why I am getting this error and why I cannot pass the person
object to removePerson(person)
? - Thanks!