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.
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.refsin the constructor will be irreversibly overwritten by an empty object{}. Other (not-obviously-reserved) names are fine, including singularthis.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.refsis a small section on the Refs page of the docs titled "Legacy API: String Refs", which does explain thatthis.refswas used in a deprecated API, but doesn't explicitly say that the name.refsis 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.refsbut none of the people answering seem to be aware of this constraint.