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
However, here's what the style guide has to say bout this:
I agree with the guide's argument and belive that it would be best to update the rule configuration to match it. Using arrow function to initialize an event handler creates a brand new function on each render same as bind() does, which can lead to unnecessary re-renders.
To be honest, I'd even turn ignoreDOMComponents to false too — it is unclear why DOM components deserve a different treatment. I'd say the reasoning from the style guide fully applies to them too.
If, however, there is some reasoning behind these exceptions — then the style guide should probably reflect it.
The text was updated successfully, but these errors were encountered:
speicus
changed the title
Configuration of react/jsx-no-bind allows to use arrow functions, while the style guide strictly prohibits it
Configuration of react/jsx-no-bind allows to use arrow functions, while the style guide prohibits it
Jul 4, 2020
Based on the coding patterns inside airbnb, tightening the rule would be too noisy and restrictive. There's no reason the guide and the linter have to be completely identical; it's totally fine if some things are left to human discernment. (Separately, .bind() is much slower than arrow functions are; the performance hit for using new arrow functions is insignificant in comparison)
DOM components don't need the same restriction regardless because the hazard is custom components rerendering too much; that's impossible for DOM elements.
The current configuration of
react/jsx-no-bind
allows to use arrow functions as event handlers (and ignores the use of bind in DOM components too): https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/rules/react.js#L104However, here's what the style guide has to say bout this:
I agree with the guide's argument and belive that it would be best to update the rule configuration to match it. Using arrow function to initialize an event handler creates a brand new function on each render same as
bind()
does, which can lead to unnecessary re-renders.To be honest, I'd even turn
ignoreDOMComponents
tofalse
too — it is unclear why DOM components deserve a different treatment. I'd say the reasoning from the style guide fully applies to them too.If, however, there is some reasoning behind these exceptions — then the style guide should probably reflect it.
The text was updated successfully, but these errors were encountered: