Skip to content

added documentation for passing arguments to event handlers #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions content/docs/handling-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
```