You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: react/README.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -274,6 +274,23 @@
274
274
275
275
## Methods
276
276
277
+
- Use arrow functions to close over local variables.
278
+
279
+
```javascript
280
+
function ItemList(props) {
281
+
return (
282
+
<ul>
283
+
{props.items.map((item, index) => (
284
+
<Item
285
+
key={item.key}
286
+
onClick={() => doSomethingWith(item.name, index)}
287
+
/>
288
+
))}
289
+
</ul>
290
+
);
291
+
}
292
+
```
293
+
277
294
- Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md)
278
295
279
296
>Why?A bind call in the render path creates a brand newfunction on every single render.
0 commit comments