Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda