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

199
Visualizações
Difference of using parentheses () and not when calling function in React

I have a question regarding calling a function in React.

Say I have this code:

function test() {
    console.log("hi");
}

Then I am implementing it like this:

        return (
            <TextField label="Name" name='itemName' value={formValues.itemName} onChange={test} />
    )

If I do it this way: test it will be fine. It will only change when I put something on the field.

But if I do it test() then the function will be triggered right away on every render.

Can someone enlighten me more about these differences? And are there any occassions where I should use the parentheses?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When you write test() you are calling the function on the spot (executing your function).

On the other hand, writing it like this test will pass a pointer to the function that needs to be executed later (onChange in your case).

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