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

167
Visualizações
React: How important it is to pass the event as parameter in the callback function?
<button 
     className="delete-btn"
     onClick={(event) => props.deleteNote(event, note.id)}
>

The code above is for a button that when clicked, calls a function that is in another component and should pass note.id as its parameter.

To my understanding, when we need to pass a function with extra parameters as props, we need to pass the whole callback function as written above.

However, I tried this version of code that doesn't include the event as the parameter for the callback function, and it seems to still work. Is there an important difference between the code snippets?

<button 
     className="delete-btn"
     onClick={() => props.deleteNote(event, note.id)}
>
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It depends on whether you need to do something with the event (like getting data from it or preventing the default action) or not. This is my opinion but i like to always pass it for good measure.

about 4 years ago · Santiago Trujillo 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