Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
React How to set an element's ref value using a variable

So I have something very simple:

<TextField ref={id}/>

I am wondering how I would use a variable as a ref, instead of a string? I kind of need this because this element is being generated in the render method, just before the return method. So I am using refs that are just created in a for loop.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

<TextField ref={(ref) => this.myRefName = ref} />

Then you can access it via this.myRefName ie console.log(this.myRefName)

over 4 years ago · Santiago Trujillo Denunciar

0

You can make use of ref callback to access ref via a variable rather than a string

<TextField ref={(input) => this.myField = input}/>

Now you can refer to TextField like this.myField

Ref callback doc

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda