airbnb / airbnb/javascript

Configuration of react/jsx-no-bind allows to use arrow functions, while the style guide prohibits it

Ouverte
#2,255 3 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
question react
Langage dominant
JavaScript
Étoiles
148k
Forks
26.6k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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#L104

![image](https://user-images.githubusercontent.com/443346/86509126-6609b600-bdee-11ea-8d7c-6a4106987078.png)

However, here's what the style guide has to say bout this:

---

![image](https://user-images.githubusercontent.com/443346/86508964-e16a6800-bdec-11ea-8979-44eb5ef15ddd.png)

---

1. 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.

2. 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.

3. If, however, there is some reasoning behind these exceptions — then the style guide should probably reflect it.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par packages/eslint-config-airbnb/rules/react.js#L104 et comparez les exceptions de react/jsx-no-bind avec les recommandations du JavaScript style guide référencé. Examinez les questions ouvertes concernant les fonctions fléchées et les composants DOM ; le travail est terminé lorsque la configuration et le guide concordent, ou que la justification du maintien d’une exception est documentée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
eslint, javascript
Domaine
documentation, tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.