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

102
Visualizações
Make an API call in a React functional component with the click of a button

I want to make an API call to the backend with the click of a button in ReactJs. I have found 3 ways that I can do that by reading stackoverflow, tutorials and articles.

  1. Add a simple function inside or outside the functional component that will make the API call (found many tutorials that use this method)

  2. Add a state variable that when changed, it will trigger the useEffect hook (with dependency to the state variable) that will make the API call

  3. Add a useCallback hook on a function and call that to make the API call

My thoughts are that the 1st is easy, simple but is it correct? And the 3rd might be wrong because you are not using the useCallback as intended (passing it to a child component and prevent re-rendering) Which way is correct (if there is another way please suggest) and why?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you need only a simple API call, I would go for option 1. Option 2 seems to me too "big" for a simple API call.

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