Edit: Specifically, does the AirBnb example below have some nuance that exempts it from the tslint rule/ SO thread in the comment by Ori Drori?
I'm using tslint-react and also following AirBnb's React style guide
AirBnb's rule "Use arrow functions to close over local variables" shows a lambda function being used in the return (render) of a pure stateless component.
function ItemList(props) {
return (
<ul>
{props.items.map((item, index) => (
<Item
key={item.key}
onClick={() => doSomethingWith(item.name, index)} // This ok??
/>
))}
</ul>
);
}
tslint-react's rule "jsx-no-lambda" seems to say this is a bad thing.
jsx-no-lambda: Creating new anonymous functions (with either the function syntax or ES2015 arrow syntax) inside the render call stack works against pure component rendering. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary.
I'm confused as to the best practice here, and whether AirBnb's style guide has a nuance that exempts it from concern.
Cheers!