Skip to content

Commit e9a67af

Browse files
authored
Merge pull request #81 from sw-yx/documentArgsIssue75
added documentation for passing arguments to event handlers
2 parents 57779b2 + 7f8d084 commit e9a67af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

content/docs/handling-events.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,12 @@ class LoggingButton extends React.Component {
139139
```
140140

141141
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.
142+
143+
## Passing arguments to event handlers
144+
145+
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:
146+
147+
```js
148+
<button onClick={() => this.deleteRow(i)}>Delete Row</button>
149+
<button onClick={this.deleteRow.bind(this, i)}>Delete Row</button>
150+
```

0 commit comments

Comments
 (0)