It uses bind , so the deletePerson method gets the correct argument person .
Since the Card component does not receive the complete person object, this allows it to identify which person the card was clicked on.
In your example, where you removed the onClick={that.deletePerson(person)} binding, it actually evaluates that.deletePerson(person) function and sets it as onClick. The deletePerson method changes the state of the component, as indicated by the error message. (You cannot change state during rendering).
The best solution might be to transfer the identifier to the Card and transfer it back to the application component when you click on delete.
var Card = React.createClass({ handleClick: function() { this.props.onClick(this.props.id) } render: function () { return ( <div> <h2>{this.props.name}</h2> <img src={this.props.avatar} alt=""/> <div></div> <button onClick={this.handleClick}>Delete Me</button> </div> ) } }) var App = React.createClass({ deletePerson: function (id) { //Delete person using id }, render: function () { var that = this; return ( <div> {this.state.people.map(function (person) { return ( <Card onClick={that.deletePerson} name={person.name} avatar={person.avatar} id={person.id}></Card> ) }, this)} </div> ) } })
Crob
source share