Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

440
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda