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

228
Vistas
Why I have to bind this to methods in class component in Reactjs

I have searched and read about this question for so long and yet still cannot wrap my head around. So in a React class component, you would write methods like this:

class Test extends React.Component {
  constructor(props){
   super(props)
   this.method = this.method.bind(this)
  }

  method() {
    ...
  }
}

If "this" is not bound by default, why can we use "this.method"? What does "this" mean in "this.method" and "bind.(this)". Are they the same?

This line: this.method = this.method.bind(this) really confuses me. Please help me explain each one of 3 "this" in this line. Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Binding a method to "this" is useful when you pass it to a child component. When you do this, it is usually to be able to change the local state of the parent component when the child component executes this method. It's kind of like saying

"I want this method to be bound to this class, that is, if it's called from anywhere, the references to "this" inside this method refer to THIS class"



Here is an interesting article that explains this in detail:
https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/

about 4 years ago · Juan Pablo Isaza 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