var CustomerTable = React.createClass({
addEmailButton: function(customerId) {
console.log(customerId);
return (
<button onClick={console.log("clicked", customerId)}>X</button>
)
},
render: function() {
var self = this;
return (
<div>
<table>
<thead>
<tr>
<th>Actions</th>
</tr>
</thead>
<tbody>
{
this.state.customers.map(function(customer, i) {
return (
<tr key={i}>
<td>{self.addEmailButton(customer['id'])}</td>
</tr>
)
})
}
</tbody>
</table>
</div>
)
}
});
Wenn diese Komponente wiedergegeben wird, wird der Aufruf console.log ausgeführt, ohne auf eine der Schaltflächen zu klicken.Reagieren beim Rendern einer Komponente löst das Ereignis onClick aus?
Ich möchte nur eine Methode aufrufen, wenn eine Schaltfläche geklickt wird, nichts wirklich kompliziert.
Warum ist das?
@Sergio Tapia konnte gibst du Feedback? –