added documentation for passing arguments to event handlers

This commit is contained in:
sw-yx
2017-10-08 14:34:03 -04:00
parent be1f9a60d8
commit 6dad6d2b7a

View File

@@ -139,3 +139,17 @@ class LoggingButton extends React.Component {
```
The problem with this syntax is that a different callback is created each time the `LoggingButton` renders. In most cases, this is fine. However, if this callback is passed as a prop to lower components, those components might do an extra re-rendering. We generally recommend binding in the constructor or using the class fields syntax, to avoid this sort of performance problem.
## Passing arguments to event handlers
Inside a loop it is common to want to pass a param to an event handler. For example if `i` is the row id:
```js
<button onClick={() => this.deleteRow(i)}>Delete Row</button>
```
or alternatively (especially if you want to avoid triggering a re-render in a child component):
```js
<button onClick={this.deleteRow.bind(this,i)}>Delete Row</button>
```