mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
Allow arrow functions in JSX props
This commit is contained in:
4
packages/eslint-config-airbnb/rules/react.js
vendored
4
packages/eslint-config-airbnb/rules/react.js
vendored
@@ -41,8 +41,8 @@ module.exports = {
|
||||
// Prevent usage of .bind() and arrow functions in JSX props
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
|
||||
'react/jsx-no-bind': [2, {
|
||||
'ignoreRefs': false,
|
||||
'allowArrowFunctions': false,
|
||||
'ignoreRefs': true,
|
||||
'allowArrowFunctions': true,
|
||||
'allowBind': false,
|
||||
}],
|
||||
// Prevent duplicate props in JSX
|
||||
|
||||
@@ -274,6 +274,23 @@
|
||||
|
||||
## Methods
|
||||
|
||||
- Use arrow functions to close over local variables.
|
||||
|
||||
```javascript
|
||||
function ItemList(props) {
|
||||
return (
|
||||
<ul>
|
||||
{props.items.map((item, index) => (
|
||||
<Item
|
||||
key={item.key}
|
||||
onClick={() => doSomethingWith(item.name, index)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
- 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)
|
||||
|
||||
> Why? A bind call in the render path creates a brand new function on every single render.
|
||||
|
||||
Reference in New Issue
Block a user