Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Nowhere in the docs does it say that `this.refs` is a reserved property name

Aberta Para iniciantes
#4,681 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
65/100
Tipo de issue
Documentação
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
javascript, react
Domínio
documentation

Direção de pesquisa

Comece pela página Refs e pela seção “Legacy API: String Refs”, que atualmente menciona this.refs sem descrever explicitamente a restrição de nome reservado. Atualize a documentação perto do início e nessa seção para que os leitores saibam que this.refs é reservado e não deve ser sobrescrito.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
JavaScript
Estrelas
11.8k
Forks
7.9k
Merge médio
16h 6min
PRs com merge (30d)
7

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de reactjs/react.dev

Todas as issues de reactjs/react.dev

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.