Browse Source

Merge pull request #81 from sw-yx/documentArgsIssue75

added documentation for passing arguments to event handlers
main
Brian Vaughn 7 years ago
committed by GitHub
parent
commit
e9a67af470
  1. 9
      content/docs/handling-events.md

9
content/docs/handling-events.md

@ -139,3 +139,12 @@ 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, either of the following would work:
```js
<button onClick={() => this.deleteRow(i)}>Delete Row</button>
<button onClick={this.deleteRow.bind(this, i)}>Delete Row</button>
```

Loading…
Cancel
Save