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

158
Visualizações
What is the difference between calling a function inside an arrow function on an onClick event? ReactJS

So I'm wondering why when I pass info into functions like this, why I have to make it an arrow function compared to an onClick where I just have the function name without the parenthesis. Does this also have something to do with why not calling the function inside an arrow function will just run the function on render, and then it won't run the function again when the div is clicked?

    return(
        <div className="slider">
            <div onClick={() => arrowClicked(-1)} className="slider-left-arrow slider-arrow"></div>
            <img className="slider-image-initial" alt="not found" src={imageArray[imageArrayPosition]} />
            <div onClick={() => arrowClicked(1)} className="slider-right-arrow slider-arrow"></div>
        </div>
    )

Instead of:

    return(
        <div className="slider">
            <div onClick={arrowClicked(-1)} className="slider-left-arrow slider-arrow"></div>
            <img className="slider-image-initial" alt="not found" src={imageArray[imageArrayPosition]} />
            <div onClick={arrowClicked(1)} className="slider-right-arrow slider-arrow"></div>
        </div>
    )
about 4 years ago · Juan Pablo Isaza
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