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

444
Vistas
Bind vs Arrow Function when passing onChange props (React)

When we pass an arrow function to an event handler i.e. onClick={() => myFunction()}, we are causing un-necessary re-renders since this is a function definition.

Instead, should onClick={myFunction.bind(this)} be used instead of the arrow function whenever we call a function on an event handler and want access to this? Since it is only using a reference to the function, we are not causing a re-render each time.

Is the above understanding correct? If so, why would we ever use an arrow function as an event handler prop? It seems that ever since the introduction of ES6, using .bind like we do here is not usually recommended, but since it would not cause unnecessary re-renders shouldn't this be the best practice?

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

0

Since it is only using a reference to the function, we are not causing a re-render each time

You're wrong.

The bind method returns a new function (so will trigger a re-render).


To avoid re-renders, make use of the useCallback hook.

Or, since you don't appear to be making use of this inside myFunction (otherwise () => myFunction() would break it), just pass myFunction itself without creating a new function.

onClick={myFunction}
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