Nowhere in the docs does it say that `this.refs` is a reserved property name
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 65/100
- Type d'issue
- Documentation
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- javascript, react
- Domaine
- documentation
Piste de recherche
Commencez par la page Refs et sa section « Legacy API: String Refs », qui mentionne actuellement this.refs sans décrire explicitement la contrainte liée aux noms réservés. Mettez à jour la documentation vers le début et dans cette section afin que les lecteurs sachent que this.refs est réservé et ne doit pas être écrasé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
When creating multiple refs for a component class, it isn't unlikely that an unaware developer, wanting to add an array of refs to their component, would choose to use the property name this.refs.
It seems however that React uses this property name internally and so assigning to this.refs in the constructor will be irreversibly overwritten by an empty object {}. Other (not-obviously-reserved) names are fine, including singular this.ref.
I assume that this isn't a bug with react (although maybe?), but this constraint isn't mentioned explicitly in the Reactjs.org docs. The only mention of this.refs is a small section on the Refs page of the docs titled "Legacy API: String Refs", which does explain that this.refs was used in a deprecated API, but doesn't explicitly say that the name .refs is still reserved and can't be used.
It should probably be mentioned explicitly somewhere on that page, preferably both near the top and in that particular section. It took me quite a while of debugging to incidentally try a different name and stumble upon this issue. There are also several StackOverflow questions from other people asking why their refs aren't working when they are using this.refs but none of the people answering seem to be aware of this constraint.
- Langage dominant
- JavaScript
- Étoiles
- 11.8k
- Forks
- 7.9k
- Merge moyen
- 16 h 6 min
- PR mergées (30 j)
- 7
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de reactjs/react.dev
-
type: documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
-
bug: unconfirmed
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
-
type: typos
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
-
bug: unconfirmed
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Toutes les issues de reactjs/react.dev
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
docToolchain/docToolchain#1705 ·
-
Timezone select lists one option per character; duplicate "Failed" reason; shared tracker popover id Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
nightscout/nocturne#1414 ·
-
bug v2
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
modelcontextprotocol/inspector#2458 · 1 commentaire ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
carbon-design-system/ibm-products#9907 ·